How to resolve the algorithm Lucas-Lehmer test step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Lucas-Lehmer test step by step in the ERRE programming language

Table of Contents

Problem Statement

Lucas-Lehmer Test: for

p

{\displaystyle p}

an odd prime, the Mersenne number

2

p

− 1

{\displaystyle 2^{p}-1}

is prime if and only if

2

p

− 1

{\displaystyle 2^{p}-1}

divides

S ( p − 1 )

{\displaystyle S(p-1)}

where

S ( n + 1 )

( S ( n )

)

2

− 2

{\displaystyle S(n+1)=(S(n))^{2}-2}

, and

S ( 1 )

4

{\displaystyle S(1)=4}

.

Calculate all Mersenne primes up to the implementation's maximum precision, or the 47th Mersenne prime   (whichever comes first).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Lucas-Lehmer test step by step in the ERRE programming language

Source code in the erre programming language

PROGRAM LL_TEST

!$DOUBLE

PROCEDURE LUCAS_LEHMER(P%->RES)
     LOCAL I%,MP,SN
     IF P%=2 THEN RES%=TRUE EXIT PROCEDURE END IF
     IF (P% AND 1)=0 THEN RES%=FALSE EXIT PROCEDURE END IF
     MP=2^P%-1
     SN=4
     FOR I%=3 TO P% DO
        SN=SN^2-2
        SN-=(MP*INT(SN/MP))
     END FOR
     RES%=(SN=0)
END PROCEDURE

BEGIN
     PRINT("Mersenne Primes:")
     FOR P%=2 TO 23 DO
        LUCAS_LEHMER(P%->RES%)
        IF RES% THEN PRINT("M";P%) END IF
     END FOR
END PROGRAM

  

You may also check:How to resolve the algorithm Rep-string step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Death Star step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Van Eck sequence step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Octave programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the Fermat programming language