34 lines
724 B
Python
34 lines
724 B
Python
from tools import number_theory
|
|
import math
|
|
|
|
def try_root(n):
|
|
root = int(n ** 0.5)
|
|
if root ** 2 == n:
|
|
return root
|
|
raise ValueError
|
|
|
|
def solve(p, k):
|
|
num, mod = divmod((3 * k + try_root(k * (4 * p - 3 * k))) * k, 2 * (p - 3 * k))
|
|
if not mod:
|
|
return num
|
|
raise ValueError
|
|
|
|
def try_n(p, offset):
|
|
for k in range(int(p * offset) + 1, p // 3 + 1):
|
|
try:
|
|
return solve(p, k), k / p
|
|
except:
|
|
pass
|
|
|
|
def find(limit):
|
|
offset = 0
|
|
for p in number_theory.make_prime(limit):
|
|
try:
|
|
solve, offset = try_n(p, offset)
|
|
print(solve, offset)
|
|
yield solve
|
|
except:
|
|
pass
|
|
|
|
print(list(find(1000000)))
|