Solving Problem 3 of Projecteurler