from math import sqrt import time import sys def rng long sqrt while y

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from math import sqrt
import time
import sys
def rng(n):
i = long(sqrt(n))
while i>=0:
yield i
i=i-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 = long(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