Consider the fraction, , where n and d are positive
integers. If and , it is called a reduced
proper fraction. If we list the set of reduced proper fractions for
in ascending order of
size, we get:
It can be seen that there are
elements in this set.
How many elements would be contained in the set of reduced proper
fractions for ?
N = 1000000 phi = [i for i inrange(N + 1)] for i inrange(2, N + 1): if i == phi[i]: for j inrange(i, N + 1, i): phi[j] //= i phi[j] *= i - 1 ans = sum(phi) - 1 print(ans)