Anonymous user
Carmichael 3 strong pseudoprimes: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.
m (→{{header|REXX}}: added/changed comments and whitespace, optimized a DO loop.) |
|||
Line 1,974:
<lang rexx>/*REXX program calculates Carmichael 3─strong pseudoprimes (up to and including N). */
numeric digits 18 /*handle big dig #s (9 is the default).*/
parse arg N .; if N=='' | N=="," then N=61
tell= N>0; N= abs(N)
#=
@.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1; @.17=1; @.19=1; @.23=1; @.29=1; @.31=1
/*[↑] prime number memoization array. */
do p=3 to N by 2; pm= p-1;
if \isPrime(p) then iterate; nps= -p*p
do h3=2
gPM= g * pm /*define a couple of shortcuts for pgm.*/
/* [↓] perform some weeding of D values*/
do d=1 for g-1; if gPM // d \== 0 then iterate
if npsH3 \== d//h3 then iterate
q= 1 + gPM
r= 1 +
if \isPrime(r) then iterate
#= # + 1; c.q= r
if bot==0 then bot= q; bot= min(bot, q); top= max(top, q)
end /*d*/
end /*h3*/
$= /*
if tell
end /*j*/
if $\=='' then say 'Carmichael number: ' strip($)
end /*p*/
say
Line 2,004 ⟶ 2,005:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPrime: parse arg x; if @.x then return 1
if x<37 then return 0; if x//2==0 then return 0; if x// 3==0 then return 0
parse var x '' -1 _;
if x//11==0 then return 0; if
if x//19==0 then return 0; if x//23==0 then return
do k=29 by 6
end /*k*/
@.x=1; return 1</lang>
'''output''' when using the default input:
<pre>
|