You are viewing a single comment's thread. Return to all comments →
from math import sqrt def f(d, p): if d < 0: return 0 ret = set() D1 = d * d + 4 * p if D1 >= 0: a = round((d - sqrt(D1)) / 2) if a * (d - a) == -p: ret.add((a, d - a)) a = round((d + sqrt(D1)) / 2) if a * (d - a) == -p: ret.add((a, d - a)) a = round((-d - sqrt(D1)) / 2) if a * (-d - a) == -p: ret.add((a, -d - a)) a = round((-d + sqrt(D1)) / 2) if a * (-d - a) == -p: ret.add((a, -d - a)) return len(ret) t = int(input()) for _ in range(t): d, p = map(int, input().split()) print(f(d, p))
Seems like cookies are disabled on this browser, please enable them to open this website
Difference and Product
You are viewing a single comment's thread. Return to all comments →