Task

Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors.

For the purpose of this task,   1   (unity)   may be shown as itself.



Example

      2   is prime,   so it would be shown as itself.

      6   is not prime;   it would be shown as   



2
×
3


{\displaystyle 2\times 3}

.
2144   is not prime;   it would be shown as   



2
×
2
×
2
×
2
×
2
×
67


{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}

.



Related tasks

   prime decomposition
   factors of an integer
   Sieve of Eratosthenes
   primality by trial division
   factors of a Mersenne number
   trial factoring of a Mersenne number
   partition an integer X into N primes


$ include "seed7_05.s7i";
 
const proc: writePrimeFactors (in var integer: number) is func
  local
    var boolean: laterElement is FALSE;
    var integer: checker is 2;
  begin
    while checker * checker <= number do
      if number rem checker = 0 then
        if laterElement then
          write(" * ");
        end if;
        laterElement := TRUE;
        write(checker);
        number := number div checker;
      else
        incr(checker);
      end if;
    end while;
    if number <> 1 then
      if laterElement then
        write(" * ");
      end if;
      laterElement := TRUE;
      write(number);
    end if;
  end func;
 
const proc: main is func
  local
    var integer: number is 0;
  begin
    writeln("1: 1");
    for number range 2 to 2147483647 do
      write(number <& ": ");
      writePrimeFactors(number);
      writeln;
    end for;
  end func;