# euler totient function and euler's theorem
# phi(n) = number of numbers from 1 to n that are coprime with n

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def phi(n):
    count = 0
    for i in range(1, n+1):
        if gcd(i, n) == 1:
            count += 1
    return count

for n in [7, 10, 12, 35]:
    print("phi(", n, ") =", phi(n))

# euler's theorem  a^phi(n) = 1 mod n
n = 35
a = 3
print("3 ^", phi(n), "mod 35 =", pow(a, phi(n), n))

# formula for n = p*q
print("phi(35) = (5-1)*(7-1) =", (5-1)*(7-1))
