Solution to project euler problem 2