Project Euler 400(2)

http://projecteuler.net/index.php?section=problems&id=400

O(N2)になるコードをPythonで書いたら64秒になった。