Я пытаюсь заставить уравнение (2^g - p) / x
работать с моим кодом, но я сталкиваюсь с ошибками переполнения. Мне было интересно, есть ли способ обойти эту проблему.
import math as m
import decimal as d
d.getcontext().prec = 100000000000000
variable = int(input("Enter Number: "))
def Namespace(x): # the point of this function is to put input shift variables to find a whole number result
g = 1
p = 1
D = []
while len(D) == 0:
if x < (2**g-p):
count = 0
while count != 3:
f = ((2**g)-p)/x # Here is where the Error Happens
a = m.log(f,3)
if a.is_integer == True:
c = [d.Decimal(a), d.Decimal(g)] # adds Decimal to List
D.append(c)
count = 3
else:
g += 1
count += 1
else:
g +=1
p = find_next_prime(p+1)
print(D)
def find_next_prime(n):
return find_prime_in_range(n, 2*n)
def find_prime_in_range(a, b):
for p in range(a, b):
for i in range(2, p):
if p % i == 0:
break
else:
return p
return None
Namespace(variable)