Solution to Project Euler Problem 4