Solve problem 2 of the Euler project