Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/lucas-lehmer-test/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / lucas-lehmer-test / oracle.py` 16 lines ยท 738 bytes Raw Blame History 1 # Independent reference for "Lucas-Lehmer test" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 # the exponents p <= 63 for which 2^p - 1 has no divisor up to its square root, by trial division over 4 # 2kp + 1, the only form a divisor of 2^p - 1 can take for prime p (a different method from Lucas-Lehmer) 5 def mersenne_prime(p): 6 if p < 2 or any(p % d == 0 for d in range(2, p)): 7 return False 8 m = (1 << p) - 1 9 q = 2 * p + 1 10 while q * q <= m: 11 if m % q == 0: 12 return False 13 q += 2 * p 14 return True 15 print("Mersenne primes 2^p - 1 for p <= 63, by the Lucas-Lehmer test:") 16 print(" ".join(f"M{p}" for p in range(2, 64) if mersenne_prime(p)))