Project Euler: Problem 31