Carmichael 3 strong pseudoprimes: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: changed the inner DO loop to be faster, added shortcut calculations, used a flag to suppress blank lines, increased initial prime memoization list, removed 1st version (unsorted list).) |
m (→{{header|REXX}}: removed the need for finding the minimum.) |
||
Line 801: | Line 801: | ||
/*[↓] prime # memoization array.*/ |
/*[↓] prime # memoization array.*/ |
||
do p=3 to N by 2; if \isPrime(p) then iterate /*Not prime? Skip.*/ |
do p=3 to N by 2; if \isPrime(p) then iterate /*Not prime? Skip.*/ |
||
pm=p-1; nps=-p*p; @.=0; |
pm=p-1; nps=-p*p; @.=0; max=0 /*some handy-dandy REXX variables*/ |
||
/*[↑] Carmichael |
/*[↑] Carmichael numbers are odd*/ |
||
do h3=2 to pm; g=h3+p /*find Carmichael #s for this P. */ |
do h3=2 to pm; g=h3+p /*find Carmichael #s for this P. */ |
||
gpm=g*pm; npsh3=((nps//h3)+h3)//h3 /*shortcut stuff. */ |
gpm=g*pm; npsh3=((nps//h3)+h3)//h3 /*shortcut stuff. */ |
||
Line 812: | Line 812: | ||
if \isPrime(r) then iterate |
if \isPrime(r) then iterate |
||
carms=carms+1 /*bump the Carmichael # counter. */ |
carms=carms+1 /*bump the Carmichael # counter. */ |
||
max=max(max,q); @.q=r /*find the maximum, build a list.*/ |
|||
end /*d*/ |
end /*d*/ |
||
end /*h3*/ |
end /*h3*/ |
||
$=0 /*display a list of some Carm #s.*/ |
$=0 /*display a list of some Carm #s.*/ |
||
do j= |
do j=3 to max by 2; if @.j==0 then iterate; $=1 |
||
say '──────── a Carmichael number: ' p times j times @.j |
say '──────── a Carmichael number: ' p times j times @.j |
||
end /*j*/ |
end /*j*/ |
||
if $ then say /*show |
if $ then say /*show beautification blank line.*/ |
||
end /*p*/ |
end /*p*/ |
||