Data Structures & AlgorithmsHardCodeforces Div2 B · number theory
Problem: How many integers from 1 to 100 have exactly 3 positive divisors?
Problem: How many integers from 1 to 100 have exactly 3 positive divisors?
print(sum(1 for x in range(1, 101) if sum(1 for d in range(1, x + 1) if x % d == 0) == 3))What is printed?
- A. 3
- B. 5
- C. 6
- D. 4
Correct answer: D. 4
A number has exactly three divisors only when it is p^2 for a prime p, giving 4, 9, 25 and 49. Forgetting 49 and counting 1 as a square gives the trap answers.
More Coding Interview Problems questions
- Problem: Piles of stones are 3, 4 and 5. Two players alternately remove any positive number of stones from one pile, and whoever takes the…
- Problem: A subtraction game lets a player remove 1, 3 or 4 stones. Let g(n) be the Grundy number (mex of the Grundy values reachable in…
- Problem: Two fair six-sided dice are rolled. What is the expected value of the larger of the two faces (the maximum)?
- Problem: Words apple, app, apt, bat, banana are stored in a trie that keeps a count of words passing through each node. What does the code…
- Problem: The longest subarray with equally many 0s and 1s of a = [0, 1, 0, 0, 1, 1, 0] is needed. Run the prefix-balance code and print…
- Problem: Find the 3 smallest pair sums from A = [1, 7, 11] and B = [2, 4, 6], using a heap that starts with each A element paired with…