Lucas-Lehmer test: Difference between revisions

Content deleted Content added
→‎{{header|Java}}: Combined code spaces
→‎{{header|ALGOL 68}}: calculate all Mersenne primes up to the implementation's max precision, or the 45th Mersenne prime. (Which ever comes first).
Line 3:
and only if 2**p-1 divides S(p-1) where S(n+1)=S(n)**2-2, and S(1)=4.
 
The following programs calculate all Mersenne primes up to the implementation's precision.
maximium precision, or the 45th Mersenne prime. (Which ever comes first).
 
=={{header|Ada}}==
Line 44 ⟶ 45:
Interpretor: algol68g-mk11
main:(
PRAGMAT stack=1M precision=2000120000 PRAGMAT
PROC is prime = ( INT p )BOOL:
Line 51 ⟶ 52:
ELSE
BOOL prime := TRUE;
FOR i FROM 3 BY 2 TO ENTIER sqrt(p)
WHILE prime := p MOD i /= 0 DO SKIP OD;
prime
Line 59 ⟶ 60:
IF p = 2 THEN TRUE
ELSE
LONG LONG INT m p := LONG LONG 2 ** p - 1, s := 4;
FROM 3 TO p DO
s := (s * s - 2) MOD m p
Line 66 ⟶ 67:
FI;
INT upb prime = ENTIER(SHORTEN long log(SHORTENlong LONGbits LONGwidth REAL(long- long1 max) OVER int))/log(2)/2); # no unsigned #
INT upb count = 45; # find 45 mprimes if INT has enough bits #
printf(($" Finding Mersenne primes in M[2.."g(0)"]: "l$,upb prime));
INT count:=0;
FOR p FROM 2 TO upb DOprime WHILE
IF is prime(p) THEN
IF is mersenne prime(p) THEN
printf (($" M"g(0)$,p));
count +:= 1
FI
FI;
count <= upb count
OD
DO SKIP OD
)
Output:
Finding Mersenne primes in M[2..3325333252]:
M2 M3 M5 M7 M13 M17 M19 M31 M61 M89 M107 M127 M521 M607 M1279 M2203 M2281 M3217 M4253 M4423 M9689 M9941 M11213 M19937 M21701 M23209
See also: http://www.xs4all.nl/~jmvdveer/mersenne.a68.html