Project Euler (problem 79) solution