Solve Project Euler problem 8