Project Euler 517(2)

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

昨日考えていた高速化を行ったら、6秒になった。
今日3秒かかっている部分の高速化を考えたので、まだ速くなるはず。