Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 2000] have an odd number of positive divisors? Run the code.
Problem: How many integers in [1, 2000] have an odd number of positive divisors? Run the code.
print(sum(1 for x in range(1, 2001) if sum(1 for d in range(1, x + 1) if x % d == 0) % 2 == 1))What is printed?
- A. 1000
- B. 44
- C. 88
- D. 1956
Correct answer: B. 44
Only perfect squares have an odd divisor count, and 44² = 1936 ≤ 2000 < 45² = 2025, so 44. Half of 2000 is a guess, 88 double-counts the pairs, and 1956 counts the even-divisor numbers.
More Coding Interview Problems questions
- Problem: How many 3-element subsets of {1, ..., 10} have sum 15? Run the code. python from itertools import combinations print(sum(1 for c…
- Problem: What is the largest k such that 2^k divides 12!? Run the code. python n = 12 c = 0 p = 2 while p <= n: c += n // p p = 2 print(c)…
- Problem: What is the length of the longest common prefix of 'interview', 'internet' and 'interval'? Run the code. python import os…
- Problem: How many subsets of {1, ..., 7} contain no two numbers that differ by exactly 1? Run the code. python print(sum(1 for m in…
- Problem: What is the minimum number of moves to sort [4, 1, 3, 2] when one move takes any element to the front? Run the code (answer = n…
- Problem: What is the running time of Ford-Fulkerson when augmenting paths are found by DFS with integer capacities?