Project Euler 354(2)

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

あれからなにも工夫せずに組んでみたら、30秒。でもincorrect。なにが間違っているのかわからない。