Project Euler solution