Solution to Project Euler Problem 10