Solution to Project Euler problem 14.