Project Euler 373

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

S(100)出た。しかし、絶望的に何も思いつかない。
やっとS(1200)出た、と思ったら微妙に値が違うなあ。またかぶっているのか。しかも10万でも40秒。