ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
import math
def ndiv(n):
c = 0
for i in range(1, math.isqrt(n) + 1):
if n % i == 0:
c += 1 if i * i == n else 2
return c
print(ndiv(36), ndiv(37), ndiv(1))- A. 9 2 2
- B. 8 2 1
- C. 9 2 1
- D. 9 1 1
Correct answer: C. 9 2 1
Divisors come in pairs i and n // i, which is why the loop adds 2, except when i is the exact square root. 36 has nine divisors, 37 is prime with two, and 1 has one.
More Python Programming questions
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def mid(h): slow = fast = h while fast and…
- What is printed? python from collections import Counter print(''.join(c n for c, n in Counter('tree').mostcommon()))
- What is printed? python import itertools print(len(set(itertools.permutations('aab'))), len(list(itertools.permutations('aab'))))
- What is printed? python print(list(zip([iter(range(6))] 2)))
- What is printed? python print(sum(range(106)) % 7)
- What is printed? python print(12 & -12, 12 ^ 12 >> 1)