Miller–Rabin primality test: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: folded one statement.) |
m (→{{header|REXX}}: added a comment to the REXX section header.) |
||
Line 2,899: | Line 2,899: | ||
This would be in the same vein as: |
This would be in the same vein as: |
||
3 is prime, 5 is prime, 7 is prime, all odd numbers are prime. |
3 is prime, 5 is prime, 7 is prime, all odd numbers are prime. |
||
The '''K''' (above) is signified by the REXX variable '''times''' in the REXX program below. |
|||
<br>To make the program small, the true prime generator was coded to be small, but not particularly fast. |
<br>To make the program small, the true prime generator was coded to be small, but not particularly fast. |
||
<lang rexx>/*REXX program puts the Miller─Rabin primality test through its paces. */ |
<lang rexx>/*REXX program puts the Miller─Rabin primality test through its paces. */ |
||
parse arg limit |
parse arg limit times . /*obtain optional arguments from the CL*/ |
||
if limit=='' | limit==',' then limit=1000 /*Not specified? Then use the default.*/ |
if limit=='' | limit==',' then limit=1000 /*Not specified? Then use the default.*/ |
||
if |
if times=='' | times==',' then times= 10 /* " " " " " " */ |
||
numeric digits max(200, 2*limit) /*we're dealing with some ginormous #s.*/ |
numeric digits max(200, 2*limit) /*we're dealing with some ginormous #s.*/ |
||
tell= |
tell= times<0; pad=left('', 7) /*show primes only if times is negative*/ |
||
times=abs(times); w=length(times) /*use absolute value of TIMES; get len.*/ |
|||
call genPrimes limit /*suspenders now, use a belt later ··· */ |
call genPrimes limit /*suspenders now, use a belt later ··· */ |
||
@MRpt= 'Miller─Rabin primality test' /*define a character literal for SAY. */ |
@MRpt= 'Miller─Rabin primality test' /*define a character literal for SAY. */ |
||
say "There are" # 'primes ≤' limit /*might as well display some stuff. */ |
say "There are" # 'primes ≤' limit /*might as well display some stuff. */ |
||
say /* [↓] (skipping unity); show sep line*/ |
say /* [↓] (skipping unity); show sep line*/ |
||
do a=2 to |
do a=2 to times; say copies('─',89) /*(skipping unity) do range of TIMEs.*/ |
||
mrp=0 /*counter of primes for this pass. */ |
mrp=0 /*counter of primes for this pass. */ |
||
do z=1 for limit /*now, let's get busy and crank primes.*/ |
do z=1 for limit /*now, let's get busy and crank primes.*/ |