Beispiel #1
0
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():
    # 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)
Beispiel #3
0
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():
    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)