Lucas-Lehmer test: Difference between revisions
Content added Content deleted
m (→{{header|Ada}}: Simplified code) |
m (→{{header|Python}}: remove comments, rename variables, and include some optimiser hints) |
||
Line 59:
LONG LONG INT m p := LONG LONG 2 ** p - 1, s := 4;
FROM 3 TO p DO
s := (s **
OD;
s = 0
Line 191:
from sys import stdout
from math import sqrt, log
fi = od = None
def is_prime ( p ):
if p == 2
elif p <= 1 or p % 2 == 0
else:
prime = True;
for i in range(3, int(sqrt(p))+1, 2 ): # do
else:
return True
fi
fi;
def is_mersenne_prime ( p ):
if p == 2
else:
m_p =
for i in range(3, p+1): # do
s = (s **
od;
return s == 0
fi;
precision = 20000; # maximum requested number of decimal places of 2 ** MP-1 #
upb_prime = int(
upb_count = 45; # find 45 mprimes if int
print ((" Finding Mersenne primes in M[2..%d]:
count=0;
for p in range(2, upb_prime+1): # do
if is_prime(p)
count +=
fi;
if count >= upb_count
od
print
Output:
Finding Mersenne primes in M[2..33218]:
|