Project Euler 506

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

18着。
すぐに解法思いついたのに、デバッグにえらく時間がかかってしまった。