from math import sqrt import time import sys def rng return xrange int

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from math import sqrt
import time
import sys
def rng(n):
return xrange(int(sqrt(n)),0,-1)
def squ(n):
for i in rng(n):
for j in rng(n-i**2):
for k in rng(n-i**2-j**2):
m = n-(i**2+j**2+k**2)
if m>=0:
sm = int(sqrt(m))
if sm == sqrt(m): return [i,j,k,sm]
start_time = time.time()
print squ(int(sys.argv[1]))
print time.time() - start_time