Anonymous user
Miller–Rabin primality test: Difference between revisions
→{{header|REXX}}: added/changed comments and whitespace, changed indentations, optimized the inner DO loop in the M_Rt function.
(→{{header|REXX}}: added/changed comments and whitespace, changed indentations, optimized the inner DO loop in the M_Rt function.) |
|||
Line 3,816:
if times=='' | times=="," then times= 10 /* " " " " " " */
numeric digits max(200, 2*limit) /*we're dealing with some ginormous #s.*/
tell= times<0
times=abs(times);
call
@
say "There are" # 'primes ≤'
say /* [↓] (skipping unity); show sep line*/
if
p=p + 1
if tell then say z
say '[K='a"] "
▲ end /*z*/
end /*a*/
▲ say pad 'for 1──►'limit", K="right(a,w)',' @MRpt "found" mrp 'primes {out of' #"}."
▲ end /*a*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Miller_Rabin: procedure; parse arg n,k /*Miller─Rabin: A.K.A. Rabin─Miller.*/▼
do j=@.#+2 by 2
do k=2 while
end /*j*/;
/*──────────────────────────────────────────────────────────────────────────────────────*/▼
do while d//2==0; d=d%2; s=s+1; end /*while ···*/▼
if n==2
if n<2 | n//2==0 then return 0 /*check for too low, or an even number.*/
end /*while*/
return 1
▲/*──────────────────────────────────────────────────────────────────────────────────────*/
▲genPrimes: parse arg high; @.=0; !.=0; @.1=2; @.2=3; !.2=1; !.3=1; #=2
▲ #=#+1; @.#=j; !.j=1 /*bump the prime counter; add prime to */
▲'''output''' when using the input of: <tt> 10000 10 </tt>
<pre>
There are 1229 primes ≤ 10000
|