Lucas-Lehmer test for Mersenne numbers (Python)
From LiteratePrograms
This program is a code dump.
Code dumps are articles with little or no documentation or rearrangement of code. Please help to turn it into a literate program. Also make sure that the source of this code does consent to release it under the MIT or public domain license.
def lucas_lehmer(p):
s = 4
m = (2 ** p) - 1
for i in range(0, p - 2):
s = ((s * s) - 2) % m
return (s == 0)
| Download code |