The task is: Given a positive integer n, find the number of ordered tuples (a, b, c, d, e) over non-negative integers for which a² + b² + c² + d² = n and b + 3c + 5d = e².
n = int(input())
count = 0
for e in range(3 * math.floor(math.sqrt(math.sqrt(n))) + 2):
for c in range(math.floor(math.sqrt(n)) + 1):
for b in range(math.floor(math.sqrt(n)) + 1):
if (e**2-b-3*c)/5 == int((e**2-b-3*c)/5) and (e**2-b-3*c) >= 0:
for a in range(math.floor(math.sqrt(n)) + 1):
if a**2 +(26*b**2+6*b*c-2*e**2*b+34*c**2-6*e**2*c+e**4)/25 == n:
count += 1
print(count)
e
, especially not when the range-formula doesn't seem to be correct. Also, working with float divisions in(e**2-b-3*c)/5 == int((e**2-b-3*c)/5)
is prone to floating-point approximations;(e**2-b-3*c) % 5 == 0
seems less dangerous. Even better could be to calculateb = e**2-5*d-3*c
without needing a division. Fora
no loop is needed, just test whethern - b**2 - c**2 - d**2
is a square.if n - (26*b**2+6*b*c-2*e**2*b+34*c**2-6*e**2*c+e**4)/25 >= 0 and math.sqrt(n - (26*b**2+6*b*c-2*e**2*b+34*c**2-6*e**2*c+e**4)/25) == int(math.sqrt(n - (26*b**2+6*b*c-2*e**2*b+34*c**2-6*e**2*c+e**4)/25)) :