Advertisement
danchaofan

Euler #70

Dec 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def factorize(n):
  2.     factors = []
  3.     while n % 2 == 0:
  4.         factors.append(2)
  5.         n = int(n/2)
  6.     for b in range(3, int(n**0.5) + 1, 2):
  7.         while n % b == 0:
  8.             n = int(n/b)
  9.             factors.append(b)
  10.     if n > 2:
  11.         factors.append(int(n))
  12.     return set(factors)
  13.  
  14.  
  15. def totient(n):
  16.     coprimes = n
  17.     for x in factorize(n):
  18.         coprimes *= (1-(1/x))
  19.     if sorted(str(int(coprimes))) == sorted(str(n)):
  20.         return coprimes
  21.     return 1
  22.  
  23. bestratio, best = 10**10, 0
  24. for y in range(2, 10**7):
  25.     print(y)
  26.     if y/totient(y) < bestratio:
  27.         bestratio = y/totient(y)
  28.         best = y
  29. print(best)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement