Carmichael 3 strong pseudoprimes: Difference between revisions

m
→‎{{header|REXX}}: made some cometic changes, removed calculation with even prime (Carmicahael numbers can't be even). -- ~~~~
m (→‎{{header|REXX}}: made some cometic changes, removed calculation with even prime (Carmicahael numbers can't be even). -- ~~~~)
Line 283:
<lang rexx>/*REXX program calculates Carmichael 3-strong pseudoprimes. */
numeric digits 30 /*in case user wants bigger nums.*/
parse arg hN .; if hN=='' then hN=61 /*allow user to specify the limit*/
if 1=='f1'x then times='af'x /*if EBCDIC machine, use a bullet*/
else times='f9'x /* " ASCII " " " " */
carms=0 /*number of Carmichael #s so far.*/
!.=0 /*a method of prime memoization. */
do p=3 to N by 2; if \isPrime(p) then iterate /*Not prime? Skip.*/
 
pm=p-1; do jnps=1-p*p to h by 2; p=j; if p==1 then p=2 /*couple of handy-dandy variables*/
if \isPrime(p) then iterate do h3=2 to pm; g=h3+p /*Notfind prime?Carmichael #s Thenfor keepthis truckin'P. */
pm=p-1 do d=1 to /*use this for "prime less one." */g-1
nps=-p*p if g*pm//d\==0 | ((nps/*another/h3)+h3)//h3\==d//h3 handy-dandy variable.then */iterate
q=1+pm*g%d; if \isPrime(q) | q==p then iterate
 
do h3=2 to pm; gr=h31+p*q%h3; if \isPrime(r) | q*r//pm\==1 then iterate
say '──────── a Carmichael number: ' p times q times r
do d=1 to g-1
carms=carms+1 /*bump the Carmichael # counter. */
if g*pm//d\==0 | ((nps//h3)+h3)//h3\==d//h3 then iterate
q=1+pm*g%d; ifend \isPrime(q) | q==p then iterate/*d*/
r=1+p*q%h3; end if \isPrime(r) | q/*h3*r//pm\==1 then iterate
say say '──────── a Carmichael number: ' p times q /*show timesbueatification blank rline.*/
carms=carms+1 end /*bump the Carmichael # counter. p*/
end /*d*/
end /*h3*/
say /*show bueatification blank line.*/
end /*j*/
 
say; say carms ' Carmichael numbers found.'
exit /*stick a fork in it, we're done.*/
Line 312 ⟶ 307:
if wordpos(x,'2 3 5 7')\==0 then do; !.x=1; return 1; end
if x<11 then return 0; if x//2==0 then return 0; if x//3==0 then return 0
do i=5 by 6 until i*i>x; if x// i if x//(i+2)==0 then return 0
 
do i=5 by 6 until i*i>x; if x//(i+2) ==0 then return 0
if x//(i+2)==0 then return 0
end /*i*/
!.x=1; return 1</lang>
return 1</lang>
'''output''' when using the default input
<pre style="height:30ex;overflow:scroll">