Last active
October 1, 2021 05:53
-
-
Save markusait/369811561ece94711420fcefa37e40cb to your computer and use it in GitHub Desktop.
solequa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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