Lucas-Lehmer test: Difference between revisions

m
→‎{{header|Python}}: remove comments, rename variables, and include some optimiser hints
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 ** s2 - 2) MOD m p
OD;
s = 0
Line 191:
from sys import stdout
from math import sqrt, log
fi = od = None
def is_prime ( p ):
if p == 2 : return True
elif p <= 1 or p % 2 == 0 : return False
else:
prime = True;
for i in range(3, int(sqrt(p))+1, 2 ): # do
#if print "p % i == 0:",p return False
if p % i == 0 : return False
else:
return True
fi
fi;
def is_mersenne_prime ( p ):
if p == 2 : return True
else:
m_p = 2( **1 << p ) - 1; s = 4;
for i in range(3, p+1): # do
s = (s ** s2 - 2) % m_p
od;
return s == 0
fi;
precision = 20000; # maximum requested number of decimal places of 2 ** MP-1 #
long_long_bits_widthlong_bits_width = precision / log(2) * log(10);
upb_prime = int( long_long_bits_widthlong_bits_width - 1 ) / 2; # no unsigned #
upb_count = 45; # find 45 mprimes if int haswas given enough bits #
print ((" Finding Mersenne primes in M[2..%d]: "%upb_prime));
count=0;
for p in range(2, upb_prime+1): # do
if is_prime(p) :and is_mersenne_prime(p):
if is_mersenne_primeprint("M%d"%p) :,
stdout.writeflush(" M%d"%p);
count += stdout.flush();1
count += 1
fi
fi;
if count >= upb_count : break; fi
od
print
 
Output:
Finding Mersenne primes in M[2..33218]: