Lucas-Lehmer test: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 1,267: Line 1,267:
<lang RPL>
<lang RPL>
%%HP: T(3)A(R)F(.); ; ASCII transfer header
%%HP: T(3)A(R)F(.); ; ASCII transfer header
\<< DUP LN DUP \pi * 4 SWAP / 1 + UNROT / * IP 2 { 2 } ROT 2 SWAP ; input n; n := n/ln(n)*(1 + 4/(pi*ln(n))), p : = 2 ; (n ~ number of primes less then n, pi used here only as a convenience), 2 is assumed to be the 1st elemente in the list
\<< DUP LN DUP \pi * 4 SWAP / 1 + UNROT / * IP 2 { 2 } ROT 2 SWAP ; input n; n := n/ln(n)*(1 + 4/(pi*ln(n))), p:=2; (n ~ number of primes less then n, pi used here only as a convenience), 2 is assumed to be the 1st elemente in the list
START SWAP NEXTPRIME DUP UNROT DUP 2 SWAP ^ 1 - 4 PICK3 2 - 1 SWAP ; for i := 2 to n
START SWAP NEXTPRIME DUP UNROT DUP 2 SWAP ^ 1 - 4 PICK3 2 - 1 SWAP ; for i := 2 to n, p := nextprime; s := 4; m := 2^p - 1;
START SQ 2 - OVER MOD ; p := nextprime; s := 4; m := 2^p - 1;
START SQ 2 - OVER MOD ; for j := 1 to p - 2; s := s^2 mod m;
NEXT NIP NOT { + } { DROP } IFTE ; for j := 1 to p - 2; s <- s^2 mod m;
NEXT NIP NOT { + } { DROP } IFTE ; next j; if s = 0 then add p to the list else discard p;
NEXT NIP ; next j; if s = 0 then add p to the list else discard p
NEXT NIP ; next i;
\>> ; next i
\>>
</lang>
</lang>
{{out}}
{{out}}
Line 1,281: Line 1,281:
{ 2 3 5 7 13 17 19 31 61 89 107 127 521 607 1279 2203 2281 }
{ 2 3 5 7 13 17 19 31 61 89 107 127 521 607 1279 2203 2281 }


These take 1m 22s on the real HP 50g and 4m 29s and 10h 29m 23s on the emulator (Debug4 running on PC under WinXP @ 1.86GHz), respectively.
These take 1m 22s on the real HP 50g and 4m 29s and 10h 29m 23s on the emulator (Debug4 running on PC under WinXP, Intel(R) Core(TM) Duo CPU T2350 @ 1.86GHz), respectively.
</pre>
</pre>