View Single Post
Old 2020-10-23, 00:19   #1
Dec 2017

24010 Posts
Question if p is prime, factors of 2^p-1? - Is it possible?

Ok according to the mods and some users "Factor this" was a disaster, so they locked the thread. Yet is it all lost or not. So I got to thinking and some here would say that is a dangerous thing lol :). I have a big question for some of the python programmers here.

As you may or may not know all factors of prime numbers which use this formula 2^p-1 when p is prime and 2^p-1 does not produce a prime, the factor is prime.

Would it be possible to use a text file with many prime numbers and then access it instantaneously and apply modular arithmetic to instantly find a factor for '2^p-1' if 'p' is a prime number while using 2^p-1 and that does not produce a prime number

this is what's in my text file:

k=(3,5,7,11,13,17,19,23, 47, 223, 233)

Here is the code I have so far but its throwing this error:

File "Factor", line 6, in <module>
if (2**p-1) % (open("C:\python37\k.txt"),'r') == 0:
TypeError: unsupported operand type(s) for %: 'int' and 'tuple'

import timeit
while True:
	p = int(input("Enter a prime number: "))
	start_time = timeit.default_timer()
	for k in range(3,300,2):
		if (2**p-1) % (open("C:\python37\k.txt"),'r') == 0:
			print(timeit.default_timer() - start_time,'seconds')

Last fiddled with by ONeil on 2020-10-23 at 00:25
ONeil is offline