Project Euler 410(2)

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

コード整理したら12分になった。
もっと速くなるはず。