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


' FB 1.05.0 Win64
 
Sub getPrimeFactors(factors() As UInteger, n As UInteger)
  If n < 2 Then Return
  Dim factor As UInteger = 2
  Do
    If n Mod factor = 0 Then
      Redim Preserve factors(0 To UBound(factors) + 1)
      factors(UBound(factors)) = factor
      n \= factor
      If n = 1 Then Return
    Else
      factor += 1  
    End If    
  Loop
End Sub 
 
Dim factors() As UInteger
 
For i As UInteger = 1 To 20
  Print Using "##"; i;
  Print " = ";   
  If i > 1 Then 
    Erase factors
    getPrimeFactors factors(), i
    For j As Integer = LBound(factors) To UBound(factors)
      Print factors(j);
      If j < UBound(factors) Then Print " x ";
    Next j
    Print
  Else
    Print i
  End If
Next i 
 
Print
Print "Press any key to quit"
Sleep