Project Euler #31 Solution