StartProgram:

TextWindow.Write(

"Enter a number to factorize: "

)

number = TextWindow.ReadNumber()

If

number = 0

Then

Goto EndProgram

EndIf

TextWindow.WriteLine(

""

divisor = 2

factors[0] = 0

index = 0

' -- Test for primality of current divisor

isPrime = 1

For

i = 2

To

Math.SquareRoot(divisor)

Math.Remainder(divisor, i) = 0

isPrime = 0

Goto EndPrime

EndFor

EndPrime:

'-- Check if current divisor (which is a prime number) divides the numerator with no remainder

And

Math.Remainder(number, divisor) = 0

factors[index] = divisor

index = index + 1

number = number / divisor

Else

divisor = divisor + 1

'-- Write to TextWindow our factors' expression: if a certain factor is recurrent, its power will be shown

power = 1

i = 0

Array.GetItemCount(factors)

i > 0

factors[i] = factors[i-1]

power = power + 1

power > 1

"^"

+ power +

" "

Or

(i>0

factors[i] <> factors[i-1])

i < Array.GetItemCount(factors)

" * "

TextWindow.Write(factors[i])

' Factorize Numbers

' -----------------------------------------------------------------------------------

"Factorizing..."

"--------------------"

'-- Loop until our number hans't been reduced to 1

While

number > 1

EndWhile

'-- Clean factors array, and restart until number is void or zero

factors =

Goto StartProgram

EndProgram: