Solved problem 51 of project euler