Project Euler 300(2)

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


やれやれ。結局、C++で組んで無理矢理答えを出した。