Solution to Project Euler's problem 5