def compute(): limit = 10**6 return sum(phi_sieve(limit)[2:])
from euler import phi_sieve limit = 10**7 phis = phi_sieve(limit) def compute(): min_ratio = float('inf') min_n = -1 for n in range(3,limit, 2): phi = phis[n] if sorted([int(k) for k in list(str(phi))]) == sorted([int(k) for k in list(str(n))]): ratio = n*1.0 / phi if ratio < min_ratio: min_ratio = ratio min_n = n return min_n if __name__ == "__main__": print(compute())