Fermat numbers: Difference between revisions
Content added Content deleted
m (→factoring by trial division: changed whitespace.) |
m (→factoring by trial division: changed a comment.) |
||
Line 1,631: | Line 1,631: | ||
numeric digits 20 /*ensure enough decimal digits, for n=9*/ |
numeric digits 20 /*ensure enough decimal digits, for n=9*/ |
||
do j=0 to n; f= 2** (2**j) + 1 |
do j=0 to n; f= 2** (2**j) + 1 /*calculate a series of Fermat numbers.*/ |
||
say right('F'j, length(n) + 1)': ' |
say right('F'j, length(n) + 1)': ' f /*display a particular " " */ |
||
end /*j*/ |
end /*j*/ |
||
say |
say |
||
do k=0 to n; f= 2** (2**k) + 1; |
do k=0 to n; f= 2** (2**k) + 1; say /*calculate a series of Fermat numbers.*/ |
||
say center(' F'k": " f' ', 79, "═") |
say center(' F'k": " f' ', 79, "═") /*display a particular " " */ |
||
p= factr(f) |
p= factr(f) /*factor a Fermat number, given time. */ |
||
if words(p)==1 then say f ' is prime.' |
if words(p)==1 then say f ' is prime.' |
||
else say 'factors: ' |
else say 'factors: ' p |
||
end /*k*/ |
end /*k*/ |
||
exit 0 /*stick a fork in it, we're all done. */ |
|||
exit |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
factr: procedure; parse arg x 1 z,,? |
factr: procedure; parse arg x 1 z,,? |
||
Line 1,648: | Line 1,648: | ||
end /*k*/ /* [↑] factor X with some low primes*/ |
end /*k*/ /* [↑] factor X with some low primes*/ |
||
do y=0 by 2; |
do y=0 by 2; j= j + 2 + y // 4 /*ensure not ÷ by three. */ |
||
parse var j '' -1 _; |
parse var j '' -1 _; if _==5 then iterate /*last digit a "5"? Skip it.*/ |
||
if j*j>x | j>z then leave |
if j*j>x | j>z then leave |
||
call build /*add Y to the factors list. */ |
call build /*add Y to the factors list. */ |