Lucas-Lehmer test: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: HP-28 series version) |
m (→RPL HP-28 series: typo) |
||
Line 3,260: | Line 3,260: | ||
===RPL HP-28 series=== |
===RPL HP-28 series=== |
||
Unlike RPL implemented on HP-50 series, RPL of HP-28s has neither big integers, nor modular arithmetic operators, nor prime number test functions, nor even modulo operator for unsigned integers. |
Unlike RPL implemented on HP-50 series, RPL of HP-28s has neither big integers, nor modular arithmetic operators, nor prime number test functions, nor even modulo operator for unsigned integers. |
||
Let's |
Let's build them all... |
||
{{works with|Halcyon Calc|4.2.7}} |
{{works with|Halcyon Calc|4.2.7}} |
||
{| class="wikitable" |
{| class="wikitable" |
||
Line 3,283: | Line 3,283: | ||
≪ → m |
≪ → m |
||
≪ #1 |
≪ #1 |
||
'''WHILE''' OVER #0 > REPEAT |
'''WHILE''' OVER #0 > '''REPEAT''' |
||
IF OVER #1 AND #1 == THEN |
IF OVER #1 AND #1 == '''THEN''' |
||
3 PICK * m / LAST ROT * - END |
3 PICK * m / LAST ROT * - '''END''' |
||
SWAP SR SWAP |
SWAP SR SWAP |
||
ROT DUP * m / LAST ROT * - ROT ROT |
ROT DUP * m / LAST ROT * - ROT ROT |
||
END |
'''END''' |
||
ROT ROT DROP2 |
ROT ROT DROP2 |
||
≫ ≫ |
≫ ≫ ‘'''MODXP'''’ STO |
||
≪ 2 OVER ^ R→B 1 - → mp |
≪ 2 OVER ^ R→B 1 - → mp |
||
≪ #4 |
≪ #4 |
||
3 ROT '''FOR''' n |
3 ROT '''FOR''' n |
||
#2 mp MODXP |
#2 mp '''MODXP''' |
||
'''IF''' DUP #2 < '''THEN''' mp + '''END''' #2 - |
'''IF''' DUP #2 < '''THEN''' mp + '''END''' #2 - |
||
'''NEXT''' |
'''NEXT''' |
||
Line 3,311: | Line 3,311: | ||
if 2 or 3 divides a |
if 2 or 3 divides a |
||
return 0 |
return 0 |
||
else store |
else store sqrt(a) |
||
d = 4 ; flag 1 set while presumed prime |
d = 4 ; flag 1 set while presumed prime |
||
for n=5 to |
for n=5 to sqrt(a) |
||
if d divides a |
if d divides a |
||
prepare loop exit |
prepare loop exit |
||
d = 6-d ; n += d |
d = 6-d ; n += d |
||
clean stack, return result |
|||
Line 3,329: | Line 3,329: | ||
base = (base * base) % m; |
base = (base * base) % m; |
||
} |
} |
||
return result |
clean stack, return result |
||
} |
|||
'''MSNP?''' ''( p -- boolean )'' |
'''MSNP?''' ''( p -- boolean )'' |
||
Line 3,351: | Line 3,351: | ||
1: { 2 3 5 7 13 17 19 31 } |
1: { 2 3 5 7 13 17 19 31 } |
||
</pre> |
</pre> |
||
Runs in 48 seconds on a standard HP-28S. |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |