Skip to content

Instantly share code, notes, and snippets.

@markusait
Last active October 1, 2021 05:53
Show Gist options
  • Save markusait/369811561ece94711420fcefa37e40cb to your computer and use it in GitHub Desktop.
Save markusait/369811561ece94711420fcefa37e40cb to your computer and use it in GitHub Desktop.
solequa
import math
def isPosInt(x):
return x >= 0 and x.is_integer()
def findABs(n):
start = 2 if isPosInt(n / 2) else 1
limit = int(math.sqrt(n)) + 1
solutions = []
step = 2
for x in range(start, limit, step):
y = n / x
if isPosInt(y):
solutions.append([int(x), int(y)])
return solutions
def sol_equa(n):
abs = findABs(n)
solutions = []
for ab in abs:
a = ab[0]
b = ab[1]
y = (b - a) // 4
x = (a + b) // 2
isSolution = x ** 2 - 4 * y ** 2 == n
if isSolution:
solutions.append([int(x), int(y)])
return solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment