Advertisement
makispaiktis

Diophantine Equation

Jan 4th, 2021 (edited)
1,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. from math import sqrt
  2.  
  3. def sol_equa(n):
  4.     LIMIT = 1000
  5.     solutions = list()
  6.     for y in range(1, LIMIT):
  7.         for x in range(y, LIMIT):
  8.             if x**2 - 4 * y**2 == n:
  9.                 solutions.append([x, y])
  10.     return solutions
  11.  
  12.  
  13. def sol_equa2(n):
  14.     solutions = list()
  15.     for y in range(1, 50000):
  16.         x_squared = 4 * y**2 + n
  17.         if sqrt(x_squared) == int(sqrt(x_squared)):
  18.             solutions.append([int(sqrt(x_squared)), y])
  19.     return solutions
  20.  
  21.  
  22. # MAIN FUNCTION
  23. print(sol_equa(5))
  24. print(sol_equa(21))
  25. print(sol_equa2(90005))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement