Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: How many integers in [1, 100] have exactly two prime factors counted with multiplicity? Run the code.
Problem: How many integers in [1, 100] have exactly two prime factors counted with multiplicity? Run the code.
def omega(n):
c = 0
d = 2
while d * d <= n:
while n % d == 0:
n //= d
c += 1
d += 1
return c + (1 if n > 1 else 0)
print(sum(1 for x in range(2, 101) if omega(x) == 2))What is printed?- A. 56
- B. 34
- C. 30
- D. 74
Correct answer: B. 34
Ω(n) = 2 covers semiprimes p·q and squares p², 34 numbers up to 100. Counting two distinct prime factors gives 56, only squarefree semiprimes give 30, and Ω ≥ 2 gives 74.
More Coding Interview Problems questions
- Problem: What is the sum of all proper divisors of 220 (divisors smaller than 220)? Run the code. python print(sum(d for d in range(1…
- Problem: What is the minimum number of coins from {1, 6, 10} that sum to 37? Run the DP. python INF = 10 9 d = [0] + [INF] 37 for v in…
- Problem: How many distinct arrangements of the letters of 'MISSISSIPPI' exist? Run the code. python import math print(math.factorial(11)…
- Problem: What is the maximum total of two non-overlapping subarrays of length 2 in [1, 5, 2, 8, 3]? Run the code. python a = [1, 5, 2, 8…
- Problem: How many integers in [1, 1000] have digit sum equal to 5 and are divisible by 5? Run the code. python print(sum(1 for x in…
- Problem: Which algorithm computes the number of shortest paths between all pairs in an unweighted graph in O(V E)?