Code for problem on project euler