Commit 0a2898ef authored by Michael Krause's avatar Michael Krause 🎉
Browse files

Add mersenne exponent sequence

parent 9d6f3c1a
def llt(p):
"""Lucas-Lehmer primality test for a prime p"""
s = 4
M = 2**p - 1
for i in range(p-2):
s = (s**2 - 2)%M
if s == 0:
return True
else:
return False
......@@ -30,3 +30,13 @@ def primes(n):
if mask[i]:
primes.append(i)
return primes[0:n]
def mersenne(n):
"""return first n mersenne prime exponents"""
res = [2]
i = 3
while len(res) < n:
if helpers.llt(i):
res.append(i)
i += 1
return res
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment