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


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
runSample(arg)
return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method factor(val) public static
  rv = 1
  if val > 1 then do
    rv = ''
    loop n_ = val until n_ = 1
      parse checkFactor(2, n_, rv) n_ rv
      if n_ = 1 then leave n_
      parse checkFactor(3, n_, rv) n_ rv
      if n_ = 1 then leave n_
      loop m_ = 5 to n_ by 2 until n_ = 1
        if m_ // 3 = 0 then iterate m_
        parse checkFactor(m_, n_, rv) n_ rv
        end m_
      end n_
    end
  return rv
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method checkFactor(mult = long, n_ = long, fac) private static binary
  msym = 'x'
  loop while n_ // mult = 0
    fac = fac msym mult
    n_ = n_ % mult
    end
  fac = (fac.strip).strip('l', msym).space
  return n_ fac
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
  -- input is a list of pairs of numbers - no checking is done
  if arg = '' then arg = '1 11    89 101    1000 1020    10000 10010'
  loop while arg \= ''
    parse arg lv rv arg
    say
    say '-'.copies(60)
    say lv.right(8) 'to' rv
    say '-'.copies(60)
    loop fv = lv to rv
      fac = factor(fv)
      pv = ''
      if fac.words = 1 & fac \= 1 then pv = '<prime>'
      say fv.right(8) '=' fac pv
      end fv
    end
  return
 