Solutions to project euler, problem 47