Created
September 26, 2018 18:04
-
-
Save acwoss/bbd8738b37c23918ee66e3b0c365eb55 to your computer and use it in GitHub Desktop.
QuickDarkbluePublishers created by acwoss - https://repl.it/@acwoss/QuickDarkbluePublishers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def is_prime(number): | |
i = 3 | |
while i**2 <= number: | |
if number % i == 0: | |
return False | |
i += 2 | |
return True | |
def lucas_lehmer(p): | |
s = 4 | |
M = 2**p - 1 | |
for _ in range(p - 2): | |
s = ((s * s) - 2) % M | |
return s == 0 | |
def mersenne_primes(): | |
p = 3 | |
while True: | |
if is_prime(p) and lucas_lehmer(p): | |
yield (p, 2**p - 1) | |
p += 2 | |
start = time.time() | |
numbers = mersenne_primes() | |
for _ in range(10): | |
p, mersenne = next(numbers) | |
perfect = 2**(p-1) * mersenne | |
print(perfect) | |
print(f'Executado em {time.time()-start}s') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment