Mersenne Prime



#2

MP:

%%HP: T(3)A(R)F(.);
\<< DUP LN DUP \pi * 4 SWAP / 1 + UNROT / * IP 2 { 2 } ROT 2 SWAP
START SWAP NEXTPRIME DUP UNROT DUP 2 SWAP ^ 1 - 4 PICK3 2 - 1 SWAP
START SQ 2 - OVER MOD
NEXT NIP NOT { + } { DROP } IFTE
NEXT NIP
\>>

110 MP --> { 2 3 5 7 13 17 19 31 61 89 107 } ( 50 s, HP 50g )
607 MP --> { 2 3 5 7 13 17 19 31 61 89 107 127 521 607 } (250 s, Emulator)

References:


1) Mersenne Prime

2) Lucas–Lehmer primality test


P.S.: Version using local variables, for clarity

%%HP: T(3)A(R)F(.);
\<< DUP LN DUP \pi * 4 SWAP / 1 + UNROT / * IP 2 { 2 } ROT 2 SWAP
START SWAP NEXTPRIME DUP 2 SWAP ^ 1 - 4 \-> p m s
\<< 1 p 2 -
START s SQ 2 - m MOD 's' STO
NEXT p DUP UNROT s NOT { + } { DROP } IFTE
\>>
NEXT NIP
\>>


Edited: 6 Oct 2013, 10:43 p.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  Record Mersenne Prime Howard Owen 10 1,617 02-18-2013, 03:55 AM
Last Post: Valentin Albillo

Forum Jump: