6 added 142 characters in body

## Python, 8382797676 73 bytes

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:s,n=(s*s-2)%m,n>>1
return s<1


## Python 2, 71 bytes

def f(m):
s,n=(m!=3)*4,m/4
while-~m&m<n:s,n=(s*s-2)%m,n>>1n/2
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 83827976 bytes

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 83827976 73 bytes

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:s,n=(s*s-2)%m,n>>1
return s<1


## Python 2, 71 bytes

def f(m):
s,n=(m!=3)*4,m/4
while-~m&m<n:s,n=(s*s-2)%m,n/2
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)

5 added 6 characters in body

## Python, 83827979 76 bytes

def f(m):
s,n=mn=(m!=3and 4=3)*4,m>>2
while-~m&m<1*n~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=mn=(m!=3and 4=3)*4,m>>2
while-~m&m<1*n~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 838279 bytes

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 838279 76 bytes

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=(m!=3)*4,m>>2
while-~m&m<n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)

4 added 1 character in body

## Python, 838282 79 bytes

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1and n~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1and n~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s==0s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 8382 bytes

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1and n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1and n:
s,n=(s*s-2)%m,n>>1
return s==0

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)


## Python, 8382 79 bytes

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s<1

from __future__ import print_function

def primes(n):
""" Return a list of primes < n """
# From http://stackoverflow.com/a/3035188/4014959
sieve = [True] * (n//2)
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i//2]:
sieve[i*i//2::i] = [False] * ((n - i*i - 1) // (2*i) + 1)
return [2] + [2*i + 1 for i in range(1, n//2) if sieve[i]]

def lucas_lehmer_old(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = (s * s - 2) % m
return s == 0 and m or 0

# much faster
def lucas_lehmer(p):
m = (1 << p) - 1
s = 4
for i in range(p - 2):
s = s * s - 2
while s > m:
s = (s & m) + (s >> p)
return s == 0 or s == m and m or 0

def f(m):
s,n=m!=3and 4,m>>2
while-~m&m<1*n:
s,n=(s*s-2)%m,n>>1
return s<1

# Make a list of some Mersenne primes
a = [3]
for p in primes(608):
m = lucas_lehmer(p)
if m:
print(p, m)
a.append(m)
print()

# Test that f works on all the numbers in a
print(all(map(f, a)))

# Test f on numbers that may not be Mersenne primes
for i in range(1, 525000):
u = f(i)
v = i in a
if u or v:
print(i, u, v)
if u != v:
print('Error:', i, u, v)

3 added 8 characters in body
2 added 79 characters in body
1