Solution to Euler problem 10