Solution for Problem 2 in euler.net