Project Euler 308(3)

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


ちょっと工夫したら8秒になった。