2013-04-17 14:34:39 +08:00

42 lines
726 B
Python

gcd_ori = lambda x, y: y == 0 and x or gcd_ori(y, x % y)
def gcd(lis):
out = lis[0]
for i in lis:
out = gcd_ori(out, i)
return out
def calc(i, j):
return (i ** 2 - j ** 2, 2 * i * j, i ** 2 + j ** 2)
def make(x):
out = []
for i in xrange(2, int(x ** 0.5)):
for j in xrange(1, i):
c = calc(i, j)
if gcd(c) == 1:
out.append(sum(c))
return out
maxx = 1500000
unit = make(maxx)
out = set([])
delete = set([])
for i in unit:
n = 1
while 1:
tmp = i * n
if tmp > maxx:
break
if tmp in out:
out.remove(tmp)
delete.add(tmp)
else:
if not tmp in delete:
out.add(tmp)
n += 1
print len(out)