Project Euler 389

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

59着。
素直に書くだけの問題。でも、Pythonだとこの手のコードは遅いので、最後に一工夫。ちょっと数学を使う。