Just add up the totient functions between 2 and 10E6.
#Euler72 class Algorithms: def totient(self, n): result = float(n) i = 2 while i*i <= n: if n % i == 0: result -= result/i while n % i == 0: n /= i i += 1 if n > 1: result -= result/n return result class Problem72: def __init__(self, limit): self.limit = limit self.Euler = Algorithms() def Solution(self): count = 0 for n in range (2, self.limit+1): count += int(self.Euler.totient(n)) if n % 50000 == 0: print n return "Answer:"+str(count) if __name__ == '__main__': P = Problem72(1000000) print P.Solution()