From:"Anders Tiberg"<anders.tiberg@telia.com>
To:<filearchive@ticalc.org>
Subject: Factorer v1.21
Date: march 13, 2011

        

        Program Factorer v1.21 written by Anders Tiberg.

   

 This program is based on a prime factor program and consequently
removes the prime factors as they are found. To obtain the correct
number of combinations in between them, the augment instruction
is used.


 Factorer
:ClLCD
:Disp "Factors an integer."
:Input X
:"anders.tiberg@telia.com"
:X->Z
:{1->L1
:2->P
:While 0==mod(X,2
:Lbl A
:X/P->X
:If mod(max(L1),P
:L1->L2
:aug(L2,P*L1->L1
:End
:For(P,P+(P>2)+1,\/X,2    (the square root of X)
:While 0==mod(X,P
:Goto A
:End
:End
:DelVar(L2
:If X>1
:aug(L1,X*L1->L1
:sortA L1->L1
:Disp Z,"",dimL L1
:L1

 
 As comparison an ordinary factor program below:




 Facts
:ClLCD
:Prompt X
:X->Z
:0->I
:{1}->L1
:2+(0~mod(X,2)->F      ~ means differs from
:For(F,F,\/X,F-1
:If 0==mod(X,F
:Then
:I+2->I
:X/F->L1(I-1
:F->L1(I-(F^2==X)
:End
:End
:sortA L1->L1
:Disp Z,"",dimL L1
:L1


 The number 9,699,690 takes about 19 seconds for Factorer,
while Facts runs in round two minutes and fifty seconds.




           Questions and/or input write to: anders.tiberg@telia.com





