'********************************************* '* Factorization of an integer number * '* ----------------------------------------- * '* Sample run: * '* * '* ? 394616 * '* * '* 2 2 2 107 461 * '* * '* ----------------------------------------- * '* Ref.: "Mathématiques par l'informatique * '* individuelle (1) By H. Lehning * '* et D. Jakubowicz, Masson, Paris, * '* 1982" [BIBLI 06]. * '********************************************* 'Enter integer number to be factorized cls print input " ? ", N print 'Test if multiple of 2 50 D=N-2*INT(N/2) if D=0 then print 2; : N=N/2 : goto 50 'Test if multiple of 3 100 D=N-3*INT(N/3) if D=0 then print 3; : N=N/3 : goto 100 'Test of divisors 6i-1 and 6i+1 up to sqr(N) 'Prime numbers are of the form 6i-1 or 6i+1 for i%=6 to sqr(N)+1 step 6 150 D=N-(i%-1)*INT(N/(i%-1)) if D=0 then print i%-1; : N=N/(i%-1) : goto 150 200 D=N-(i%+1)*INT(N/(i%+1)) if D=0 then print i%+1; : N=N/(i%+1) : goto 200 next i% if N>1 then print N end 'end of file factors.bas