Anonymous user
Carmichael 3 strong pseudoprimes: Difference between revisions
→{{header|REXX}}: changed/added comments and indentations, optimized some code.
(Add rust solution) |
(→{{header|REXX}}: changed/added comments and indentations, optimized some code.) |
||
Line 1,066:
<br>The Carmichael numbers are shown in numerical order.
<br>Some code optimization was done, while not necessary for the small default number (
<lang rexx>/*REXX program calculates Carmichael 3-strong pseudoprimes (up to and including N). */
numeric digits 30 /*
parse arg N .; if N=='' then N=61 /*allow user to specify for the
carms=0
!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1; !.17=1; !.19=1; !.23=1; !.29=1; !.31=1▼
▲!.=0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1; !.17=1; !.19=1; !.23=1
do p=3 to N by 2; pm=p-1; bot=0;
@.=0
▲ if \isPrime(r) then iterate
if bot==0 then bot=q; bot=min(bot,q); top=max(top,q)
end /*d*/ /* [↑] find the minimum
end /*h3*/
$=0 /*display a list of some
do j=bot to top by 2
say '──────── a Carmichael number: ' p
end /*j*/
if $ then say /*show
end /*p*/
say; say carms ' Carmichael numbers found.'
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isPrime: procedure expose !.; parse arg x; if !.x then return 1
if x<
if x//11==0 then return 0; if x//13==0 then return 0
if x//17==0 then return 0; if x//19==0 then return 0
do
if x//(
end /*i*/
!.x=1; return 1</lang>
'''output''' when using the default input:
<pre style="height:
──────── a Carmichael number: 3 ∙ 11 ∙ 17
Line 1,182 ⟶ 1,180:
──────── a Carmichael number: 61 ∙ 1301 ∙ 19841
──────── a Carmichael number: 61 ∙ 3361 ∙ 4021
69 Carmichael numbers found.
</pre>
'''output''' when using the input of: <tt> -1000 </tt>
<pre>
1038 Carmichael numbers found.
</pre>
|