"Prime factorize"

?→N

{N}→List 1

N→M

0→I

Lbl 1

If M<2 or Int M≠M

Then Goto 9

IfEnd

While MOD(M,2)=0

I+1→I

2→List 1[I]

MÃ·2→M

WhileEnd

1→K

Lbl 2

If M=1 Or K>M

Then Goto 9

IfEnd

K+2→K

If M=N And K>√N

Then Goto 9

IfEnd

While MOD(M,K)=0

I+1→I

K→List 1[I]

MÃ·K→M

WhileEnd

Goto 2

Lbl 9

List 1

There is some inefficiency in the program because after it finishes finding the divisors of 2 (if there are any) to the input number, it thereafter checks to see whether all of the odd-integers might be a divisor, whether the odd-integer is a prime or not. However, it seems to me that filtering out the composite odd-integers will require tests that might consume as much CPU time as just going ahead with the check.

This code will not work on the original fx-9860g calculator until you replace two lines.

While MOD(M,2)=0

is replaced by

While MÃ·2−Int(MÃ·2)=0

While MOD(M,K)=0

is replaced by

While MÃ·K−Int(MÃ·K)=0

However, when this is done, the Casio fx-9860g performs the same task in only 25.8 seconds, which is only 67.5% of the time required by its successor model, the fx-9860gii.

If anybody can create a speedier SHORT prime factorization code for the fx-9860gii SD, I'd like to see it in format like above shown.

**Edited by Jenab6, 11 December 2010 - 07:03 PM.**