Solution of Project Euler #14