Project Euler 382

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

だいたいわかったが、計算がきつすぎる。高校生でもないのにこんな計算できない。