Solution for project euler by python 2.7