Project Euler 257

プロジェクトオイラー
http://projecteuler.net/index.php?section=problems&id=257


図形の問題かと思いきや、ちょっと計算すると、単なる整数の問題であることがわかる。


from itertools import imap

def gen_triangle(s_limit):
for b in range(1, s_limit - 1):
for c in range(1, s_limit - b):
for a in range(1, s_limit - b - c + 1):
yield a, b, c

def is_integral(t):
a, b, c = t
return ( (a + b) * (a + c)) % (b * c) == 0

N = 100
print sum(imap(is_integral, gen_triangle(N)))

1億だと厳しい。問題が出てからもうずいぶん時間が経っているのにまだほとんど解けていないみたいだし、また難問のようだ。