"Factor This" in python
by kemiy from LinuxQuestions.org on (#6F946)
Ah the speed for the first 101 non-Mersenne Primes where 2^p-1 when p is the inputted number.
For under 101 when I typed in 67 it took the longest with this output:
Enter a prime number: 67
193707721
93.221183 seconds
Yet most numbers would come back like this:
Enter a prime number: 1741
1002817
1.8384916000000002 seconds
Remember its 2^1741-1 so its a very large number that's is some speed eh hoser.
In some cases this App does work exceptionally well for larger number too. However, if you are going to search for 8 digit numbers derived from a prime number that's unknown to be a Mersenne Prime you may need to wait. Also you should change the range if you are going for very large numbers like 8 digit primes. Reply back and I can edit the code for you if you want to wait longer for the big factors. This current code as is returns factors from 9 digits long under 1.3 billion in size.
It is written solely in python:
So download python 3.7 and run this program:
I can turn this into an exe if anyone is interested just reply and ask cheers Happy Halloween find some scary factors k.
Code:
import timeit
print('''This application finds factors of numbers that are 2^p-1.
If the number has factors they are not Mersenne Primes,
when p (i.e. p is for prime) is the number you entered!
For most factors this program finds them
under 1.3 billion, only 9 digits. This is
for speed purposes. If you try large numbers you will wait for
no reason so change the range if you like waiting ''')
print("___________________")
while True:
p = int(input("Enter a prime number: "))
start_time = timeit.default_timer()
for z in range(7432339208719,7432339208720,2):
if ((2**p-1)% z ) == 0:
print(z)
print(timeit.default_timer() - start_time,'seconds')
break
if p == 1:
print(p,"Come on man type a larger number or vote for Biden, because he is number 1")
continue
if p == 2:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 5:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 7:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 13:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 17:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 19:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 31:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 61:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 89:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 107:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 127:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 521:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 607:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1279:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2203:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2281:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3217:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 4253:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 4423:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 9689:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 9941:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 11213:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 19937:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 21701:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 23209:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 44497:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 86243:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 110503:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 132049:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 216091:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 756839:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 859433:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1257787:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1398269:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2976221:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3021377:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 6972593:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 13466917:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 20996011:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 24036583:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 25964951:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 30402457:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 32582657:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 37156667:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 42643801:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 43112609:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 57885161:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 74207281:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 77232917:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 82569933:
print(p,"The input 'p' produces a Mersenne Prime")
continue
for x in range(3,(999999999),2):
if ((2**p-1)% x ) == 0:
print(x)
print(timeit.default_timer() - start_time,'seconds')
break
For under 101 when I typed in 67 it took the longest with this output:
Enter a prime number: 67
193707721
93.221183 seconds
Yet most numbers would come back like this:
Enter a prime number: 1741
1002817
1.8384916000000002 seconds
Remember its 2^1741-1 so its a very large number that's is some speed eh hoser.
In some cases this App does work exceptionally well for larger number too. However, if you are going to search for 8 digit numbers derived from a prime number that's unknown to be a Mersenne Prime you may need to wait. Also you should change the range if you are going for very large numbers like 8 digit primes. Reply back and I can edit the code for you if you want to wait longer for the big factors. This current code as is returns factors from 9 digits long under 1.3 billion in size.
It is written solely in python:
So download python 3.7 and run this program:
I can turn this into an exe if anyone is interested just reply and ask cheers Happy Halloween find some scary factors k.
Code:
import timeit
print('''This application finds factors of numbers that are 2^p-1.
If the number has factors they are not Mersenne Primes,
when p (i.e. p is for prime) is the number you entered!
For most factors this program finds them
under 1.3 billion, only 9 digits. This is
for speed purposes. If you try large numbers you will wait for
no reason so change the range if you like waiting ''')
print("___________________")
while True:
p = int(input("Enter a prime number: "))
start_time = timeit.default_timer()
for z in range(7432339208719,7432339208720,2):
if ((2**p-1)% z ) == 0:
print(z)
print(timeit.default_timer() - start_time,'seconds')
break
if p == 1:
print(p,"Come on man type a larger number or vote for Biden, because he is number 1")
continue
if p == 2:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 5:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 7:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 13:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 17:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 19:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 31:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 61:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 89:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 107:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 127:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 521:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 607:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1279:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2203:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2281:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3217:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 4253:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 4423:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 9689:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 9941:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 11213:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 19937:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 21701:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 23209:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 44497:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 86243:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 110503:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 132049:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 216091:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 756839:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 859433:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1257787:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 1398269:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 2976221:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 3021377:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 6972593:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 13466917:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 20996011:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 24036583:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 25964951:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 30402457:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 32582657:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 37156667:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 42643801:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 43112609:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 57885161:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 74207281:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 77232917:
print(p,"The input 'p' produces a Mersenne Prime")
continue
elif p == 82569933:
print(p,"The input 'p' produces a Mersenne Prime")
continue
for x in range(3,(999999999),2):
if ((2**p-1)% x ) == 0:
print(x)
print(timeit.default_timer() - start_time,'seconds')
break