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


 
# syntax: GAWK -f COUNT_IN_FACTORS.AWK
BEGIN {
    fmt = "%d=%s\n"
    for (i=1; i<=16; i++) {
      printf(fmt,i,factors(i))
    }
    i = 2144; printf(fmt,i,factors(i))
    i = 6358; printf(fmt,i,factors(i))
    exit(0)
}
function factors(n,  f,p) {
    if (n == 1) {
      return(1)
    }
    p = 2
    while (p <= n) {
      if (n % p == 0) {
        f = sprintf("%s%s*",f,p)
        n /= p
      }
      else {
        p++
      }
    }
    return(substr(f,1,length(f)-1))
}
 