Project Euler 384(1)

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

なんとなくわかったけど、コードにするのはなかなか難しい。