def P70(num1, num2): smallestquo = 2 # for i in range(num1,num2,1): # skimmerresult = skimmer(i) # if skimmerresult[0] == True: # if skimmerresult[3] < smallestquo: # smallestquo = skimmerresult[3] # print (skimmerresult) for i in range(num1, num2, 1): primefactors = sorted(prime_factors(i)) if len(primefactors) == 2: if ispermutation(i, (primefactors[0] - 1) * (primefactors[1] - 1)): if smallestquo > i / totient(i): smallestquo = i / totient(i) print(True, i, totient(i), smallestquo)
#!/usr/bin/python2.7 # To really make this faster, find the biggest number < 10 ** 7 which is the multiple # of two primes, where the totient function is a permutation # # This is because since phi(n) = n(1-1/p1)(1-1/p2)...(1-1/pk) # n/phi(n) = 1/((1-1/p1)(1-1/p2)...(1-1/pk)) # We want to minimise n/phi(n) by maximising (1-1/p1)(1-1/p2)...(1-1/pk) # So to maximise it, we need to minimise the number of entries (each multiplication makes it smaller) # But also make p as large as possible... import os, sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../util/python/") from totient import * def is_permutation(a, b): return sorted(str(a)) == sorted(str(b)) min_ratio = float(1000000000) min_n = 0 for n in xrange(10 ** 6, 10 ** 7): t = totient(n) if is_permutation(n, t): ratio = float(n) / float(t) if ratio < min_ratio: min_ratio = ratio min_n = n print(min_n)
def skimmer(num): tot = totient(num) if ispermutation(tot, num): return [True, num, tot, tot / num] else: return [False]
def farey_terms(n): count = 0 for i in xrange(1, n + 1): count += totient(i) return count + 1
#!/usr/bin/python2.7 import os, sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../util/python/") from totient import * max_result = 0 max_n = 2 for n in xrange(2, 1000000): n_on_phin = float(n) / totient(n) if n_on_phin > max_result: max_result = n_on_phin max_n = n print(max_n)