Solution of Project Euler Exercise 35