# TITLE: Factoring by Fermat's Method # AUTHOR: Roy F.A. Maclean # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 15Jan1998 # MAKE: CASIO # MODEL: fx6300G or greater # SIZE: 179 # NOTES: Enter a positive integer. If it is composite it will be # broken into 2 factors. @@ Program 1 Lbl 0 ?->A:Goto 2 Lbl 1 2_ A/2->A:A=1=>Goto 0 Lbl 2 Frac .5A=0=>Goto 1 A=1=>Goto 0 Int sqrt(A)->S Frac sqrt(A)<>0=>1+S->S 2S+1->U:1->V:S^2-A->R R=0=>Goto 6 Lbl 4 R<0=>Goto 3 Lbl 5 R-V->R V+2->V R>0=>Goto 5 Lbl 3 R>=0=>Goto 7 R+U->R U+2->U Lbl 7 R<>0=>Goto 4 Lbl 6 (U+V-2)/2_ (U-V)/2->B B<>1=>B_ Goto 0