Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- limit = 10**7
- sieve = [1]*limit
- sieve[0] = 0
- sieve[1] = 0
- for i in range(0, int(sqrt(limit))):
- j = 2
- if sieve[i] != 0:
- while(i*j < limit):
- sieve[i*j] = 0
- j += 1
- primes = [i for i in xrange(len(sieve)) if sieve[i]]
- dic = {1 : []}
- def prime_factorization(n):
- divs = []
- if n not in dic:
- for i in primes:
- if i > n: break
- if n%i == 0:
- exp = 1
- while n%(i**exp)==0: exp += 1
- dic[n] = [[i, exp-1]] + prime_factorization(n/i**(exp-1))
- return dic[n]
- return dic[n]
- def totient(n):
- tot = 1
- for i in prime_factorization(n):
- tot *= (i[0]**(i[1]-1))*(i[0]-1)
- return tot
- def is_permutation(x, y):
- return sorted(str(x)) == sorted(str(y))
- m = 20
- n = 0
- for i in range(2,10**7):
- if i%1000==0: print i
- t = totient(i)
- if is_permutation(t, i):
- cur = float(i)/t
- if cur < m:
- print cur, t, i
- m = cur
- n = i
- print m,n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement