def main(): # for i in range(2, 10000): # if is_square(5 * i**2 + 14 * i + 1): # print(i) # print(i * 5 + 7, math.sqrt(((i * 5 + 7)**2 - 44) // 5)) # pell equation u**2 - 5 * v**2 = 44 # fundamental solutions found through trial fund_uv_s = [(17, 7), (32, 14), (112, 50), (217, 97), (767, 343), (1487, 665)] fund_x, fund_y = pell.pell(5) nuggets = [] for u, v in fund_uv_s: for _ in range(N): if u % 5 == 2: nuggets.append((u - 7) // 5) # print((u - 7) // 5, total) u, v = u * fund_x + 5 * v * fund_y, v * fund_x + u * fund_y # print(u, v) # print((u - 7) / 5) nuggets.sort() # print(nuggets) print(sum(nuggets[:N]))
def main(): # for s in range(2, 10000): # sol = rational_quad_solve(s, s + 1, -s) # if sol is not None: # x = list(filter(lambda x: x > 0, sol))[0] # # print(s, x) # # print(s + 1, 2 * s, int(math.sqrt((s + 1)**2 + 4 * s * s))) # u = s * 5 + 1 # print(u, (u ** 2 + 3) * u // 2) # Find Solution # u**2 - 5 * v**2 = -4 # x = (u**2+3) * u / 2 # y = (u**2+1) * v / 2 # fundamental solution to pell equation fund_x, fund_y = pell.pell(5, True) x, y = fund_x, fund_y # solution exists for every 2 for i in range(N * 2): x, y = pell.next_solution(5, fund_x, fund_y, x, y, True) # solve equation of the form 2*x = u**3 + 3 * u # intuition: 2*x is close to 2*u**3 # because of floating point inprecision, # starting from (2*x)**(1/3) is closer for u in range(int((2 * x)**(1 / 3)), int((2 * x)**(1 / 3)) * 2): # print((u**2 + 3) * u - x * 2) if (u**2 + 3) * u == x * 2: break # print(x, y, u) print((u - 1) // 5)
def main(): result = 0 for a, b in pell.pell(3): if a < 7: continue if 2*a+2 > 1000000000: break if (a+2) % 3 == 0: result += 2*a+2 if 2*a-2 > 1000000000: break if (a-2) % 3 == 0: result += 2*a-2 print result
def main(): areas_l = set() # fundamental solution to x^2 - 5y^2 = 1 x, y = pell.pell(5) first_x, first_y = x, y areas_l.add(get_area_l(x, y)) for _ in range(N): x, y = pell.next_solution(5, first_x, first_y, x, y) areas_l.add(get_area_l(x, y)) # fundamental solution to x^2 - 5y^2 = -1 x, y = pell.pell(5, True) first_x, first_y = x, y areas_l.add(get_area_l(x, y)) for _ in range(N): x, y = pell.next_solution(5, first_x, first_y, x, y) x, y = pell.next_solution(5, first_x, first_y, x, y) areas_l.add(get_area_l(x, y)) areas_l = sorted(areas_l) print(sum(areas_l[i][1] for i in range(N)))
def main(): threshold = 10 ** 12 fund_x, fund_y = pell.pell(2, True) prev_x, prev_y = fund_x, fund_y m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 while m < threshold: prev_x, prev_y = pell.next_solution(2, fund_x, fund_y, prev_x, prev_y, True) m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 # print(m-n, n) m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 print(n)
def main(): threshold = 10**12 fund_x, fund_y = pell.pell(2, True) prev_x, prev_y = fund_x, fund_y m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 while m < threshold: prev_x, prev_y = \ pell.next_solution(2, fund_x, fund_y, prev_x, prev_y, True) m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 # print(m-n, n) m = (prev_x + 1) // 2 n = (prev_y + 1) // 2 print(n)
def test_pell50(self): x = pell(49) y = pell(50) self.assertEqual(x, 2015874949414289041) self.assertEqual(y, 4866752642924153522)
''' Created on 2011-7-13 @author: huangkan ''' import pell max=3 ans=2 for i in range(3,1001): if i**.5!=int(i**.5): t,t2=pell.pell(i) if t>max: max=t ans=i print(ans)