Carmichael 3 strong pseudoprimes: Difference between revisions
Content deleted Content added
m →numbers in order of calculation: optimized code. -- ~~~~ |
m →{{header|REXX}}: optimized the '''IF''' statements by unrolling them. -- ~~~~ |
||
Line 277:
=={{header|REXX}}==
▲<br><br>Note that REXX's version of '''modulus''' ('''//''') is really a ''remainder'' function, so a version of
<br>the '''modulus''' function was hard-coded below (when using a negative value).
===numbers in order of calculation===
Line 425 ⟶ 423:
do h3=2 to pm; g=h3+p /*find Carmichael #s for this P. */
do d=1 to g-1
if g*pm//d\==0
r=1+p*q%h3; if q*r//pm\==1 then iterate
if \isPrime(r) then iterate
carms=carms+1 /*bump the Carmichael # counter. */
min=min(min,q); max=max(max,q); @.q=r /*build a list.*/
end /*d*/
end /*h3*/
/*display a list of some Carm #s.*/
do j=min to max by 2;
say '──────── a Carmichael number: ' p times j times @.j
end /*j*/
Line 446 ⟶ 444:
/*──────────────────────────────────ISPRIME subroutine──────────────────*/
isPrime: procedure expose !.; parse arg x; if !.x then return 1
if wordpos(x,'2 3 5 7 11 13')\==0 then do; !.x=1; return 1; end
if x<
if
do i=11 by 6 until i*i>x; if x// i ==0 then return 0
if x//(i+2) ==0 then return 0
end /*i*/
|