#Lagrange.py # every natural number is the sum of four squares (can incl. 0) #e.g. 45 = 0^2+2^2+4^2+5^2 also 0^2+0^2+3^2+6^2 import math def lagrange(n): for a in range(int(math.sqrt(n))+1): for b in range(int(math.sqrt(n))+1): for c in range(int(math.sqrt(n))+1): for d in range(int(math.sqrt(n))+1): if a*a+b*b+c*c+d*d == n: return a,b,c,d maxTry = int(input("Max range of integers")) for n in range(1,maxTry+1): (a,b,c,d) = lagrange(n) if a==None: print("NONE!!!") print(n," ",a," ",b," ",c," ",d," ",(a*a+b*b+c*c+d*d)) if a*a+b*b+c*c+d*d != n: print("ERROR!")