Project Euler problem 39