Solution to ProjectEuler Problem 4