# TITLE: Factoring by Reverse Trial Division # AUTHOR: Roy Maclean # EMAIL: rfamgm at gmail # WEB: http://www.spiderpixel.co.uk/caspro # DATE: 15Jan1998 # MAKE: CASIO # MODEL: fx6300G or greater # SIZE: 124 # NOTES: Enter a positive integer. The prime factors will be displayed. # This uses trial division starting from the sqrt(n) downwards. @@ Program "REVTRIAL" Lbl 0 ?->A:Goto 2 Lbl 1 2_ A/2->A:A=1=>Goto 0 Lbl 2 Frac .5A=0=>Goto 1 Int sqrt(A)->B Frac sqrt(A)<>0=>1+B->B Frac .5B=0=>1+B->B Lbl 4 B<=1=>Goto 6 Frac (A/B)=0=>Goto 5 B-2->B:Goto 4 Lbl 5:B_ A/B->B:Goto 3 Lbl 6:A