Project Euler 330(2)

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


やっとできた。まれにこのパターンの問題があるから困る。1分くらい。