solution for problem on Project Euler