Solution to Problem 2 of Project Euler