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))- A. 12 97 1
- B. 18 96 1
- C. 12 96 0
- 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
- What is printed? python def cntinc(a, k): dp = [[0] (k + 1) for in range(len(a))] for i in range(len(a)): dp[i][1] = 1 for j in range(i)…
- What is printed? python from itertools import count, islice print(list(zip('abc', count(10, 5))), list(islice(count(1, 2), 3)))
- What is printed? python d = {k: v for k, v in [('a', 1), ('b', 2), ('a', 3)] if v > 1} print(d, {v: k for k, v in d.items()})
- What is printed? python first, mid, last = [1, 2, 3, 4, 5] a, (b, c) = 1, (2, 3, 4) print(mid, last, b, c)
- What is printed? python def ack(m, n): if m == 0: return n + 1 if n == 0: return ack(m - 1, 1) return ack(m - 1, ack(m, n - 1))…
- What is printed? python d = {'b': 2, 'a': 2, 'c': 1} print(sorted(d.items(), key=lambda kv: (-kv[1], kv[0])), sorted(d, key=d.get))