ProgrammingVery hardGATE CS & IT · Infosys

What is printed?

What is printed?
def phi(n):
    res, p = n, 2
    while p * p <= n:
        if n % p == 0:
            while n % p == 0:
                n //= p
            res -= res // p
        p += 1
    if n > 1:
        res -= res // n
    return res
print(phi(36), phi(97), phi(1))
  1. A. 12 97 1
  2. B. 18 96 1
  3. C. 12 96 0
  4. D. 12 96 1

Correct answer: D. 12 96 1

Euler's totient removes the multiples of each prime factor. 36 = 2^2 x 3^2 gives 36 x 1/2 x 2/3 = 12, and 97 is prime, so its totient is 96.

More Python Programming questions

Exams that ask this topic