Tom O'Neil 112 #1 Posted March 3 (edited) I put together some python code that outputs if a prime produces a special Mersenne Prime number. Mersenne Prime Numbers are those that utilize a prime as its power raised to produce the Mersenne Prime. For instance this formula can make a Mersenne Prime and sometimes not 2^n-1 so 2^3-1 = 7 and 7 is a Mersenne Prime, however 2^11-1 = 2047 since 2047 is not a prime number, it is composite and even though 11 is a prime number it fails to produce a Mersenne Prime Number and that's the conundrum with 2^n-1. If you can make this code run for every prime number inputted or entered and the output returns in under 4 seconds consistently for every prime numbers entered into the trillions you would be Famous and very Rich ! print('''This code will eventually relate if a prime number is or is not a Mersenne Prime. The problem is with large numbers and division of factors and so as with Prime numbers starting at 29 the time slows down on input. Anyone who can make this code respond to every prime number of trillions of digits consecutively in less than 4 seconds, that reports back correct statements for prime numbers would become famous and win a Noble Peace Prize!''') print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$') print('_________________________________________________') import time from math import floor def divSum(n): total = 1 i = 2 while i * i <= n: if n % i == 0: total += i + floor(n // i) i += 1 return total #def solve(p, q): # return divSum(q) == divSum(q) while True: start_time = time.time() p = int(input("Enter a prime number for an attempt to produce a Mersenne Prime Number: ")) h = (pow(2,p-1)*2-1)*(pow(2,p-1)) m = (((p - 1) % 9 + 1 if p else 0)) q = (pow(2,p-1)*2-1)*(pow(2,p-1)) y = (((q - 1) % 9 + 1 if q else 0)) if (divSum(q))== h: print(p,'= n and this number produces a Mersenne Prime 2^n-1') e = int(time.time() - start_time) print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60)) Edited March 3 by Tom O'Neil 1 Share this post Link to post Share on other sites
Golden Duck 12,852 #2 Posted March 3 I don't think it would be the Peace Prize you'd win. 2 Share this post Link to post Share on other sites
Dreamer screamer 573 #3 Posted March 3 Who am I gonna have to kill to get this peace prize? 1 Share this post Link to post Share on other sites
Rlyeh 17,842 #4 Posted March 3 3 hours ago, Tom O'Neil said: If you can make this code run for every prime number inputted or entered and the output returns in under 4 seconds consistently for every prime numbers entered into the trillions you would be Famous and very Rich ! Are you saying the code doesn't work or it's too slow? Share this post Link to post Share on other sites
Rlyeh 17,842 #5 Posted March 3 (edited) floor(n // i) '//' is floor division. No need to call floor on the result. https://www.python.org/dev/peps/pep-0238/ h = (pow(2,p-1)*2-1)*(pow(2,p-1)) m = (((p - 1) % 9 + 1 if p else 0)) q = (pow(2,p-1)*2-1)*(pow(2,p-1)) y = (((q - 1) % 9 + 1 if q else 0)) What is this doing? A lot of redundant calculations here. From what I can tell Python does very few optimizations. Edited March 3 by Rlyeh 2 Share this post Link to post Share on other sites
jethrofloyd 3,996 #6 Posted March 3 What have the Nobel Peace Prize to do with mathematic and formulas? Share this post Link to post Share on other sites
Rlyeh 17,842 #7 Posted March 3 (edited) You might also want to place 'start_time' after calling input(), at the moment your measurement includes the time it takes for the user to input. Edited March 3 by Rlyeh 1 Share this post Link to post Share on other sites
Golden Duck 12,852 #8 Posted March 4 There are 54 prime numbers below 256: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251] Quote A 256-bit private key will have 115,792,089,237,316,195,423,570,985,008,687,907,853,269, 984,665,640,564,039,457,584,007,913,129,639,936 (that’s 78 digits) possible combinations. No Super Computer on the face of this earth can crack that in any reasonable timeframe. Even if you use Tianhe-2 (MilkyWay-2), the fastest supercomputer in the world, it will take millions of years to crack 256-bit AES encryption. That figure sky-rockets even more when you try to figure out the time it would take to factor an RSA private key. A 2048-bit RSA key would take 6.4 quadrillion years (6,400,000,000,000,000 years) to calculate, per DigiCert. https://www.thesslstore.com/blog/what-is-256-bit-encryption/ This is the kind of problem you are trying to solve. Share this post Link to post Share on other sites
Scholar4Truth 3,272 #9 Posted March 4 If it involves math I will pass. I just despise math. Share this post Link to post Share on other sites