[Python] How can I efficiently find integer solutions (x ≠ y) to a Diophantine equation using...

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a Python script to search for integer solutions (x, y) with x ≠ y to the following Diophantine equation:

    Here:

    • n and k are fixed small positive integers (like n = 1, k = 2),
    • x and y range from 1 to a large number (e.g., 1 to 1,000,000),
    • I only want solutions where x ≠ y.

    Aside from n = 74 and k = 24, for which we get positive integer solutions as desired, how can this code for instance be better written to generate any positive integer solutions to n,k,x,y? Or if possible what other integer solutions exist other than n = 74 and k = 24 ?

    I wrote a naive brute-force solution that checks every pair (x, y) in the range, but it's way too slow:

    n = 1
    k = 2
    limit = 10**6

    for x in range(1, limit):
    rhs = (x + k)**4 - x**4
    for y in range(1, limit):
    if x == y:
    continue
    lhs = (y + n)**4 - y**4
    if lhs == rhs:
    print(f"Match found: x = {x}, y = {y}")

    Continue reading...

Compartilhe esta Página