Solution to ProjectEuler problem 1