Data Structures & AlgorithmsHardCodeforces Div2 C · divisor counting
Problem: How many integers in [1, 100] have exactly 4 positive divisors? Run the code.
Problem: How many integers in [1, 100] have exactly 4 positive divisors? Run the code.
print(sum(1 for x in range(1, 101) if sum(1 for d in range(1, x + 1) if x % d == 0) == 4))What is printed?
- A. 24
- B. 32
- C. 28
- D. 30
Correct answer: B. 32
Numbers with exactly 4 divisors are p^3 or p*q for distinct primes; in [1, 100] these are 8, 27 and 30 semiprimes, 32 in total.
More Coding Interview Problems questions
- Problem: What is the maximum number of pairwise non-overlapping non-empty subarrays of [1, -1, 2, -2, 3, -3] each having sum zero? Run the…
- Problem: How many 3-element subsets of {1, 2, 3, 4, 5, 6} have a sum divisible by 3? Run the code. python from itertools import…
- Problem: Minimum number of deletions so that no two adjacent characters of 'aaabbb' are equal. Run the code. python s = 'aaabbb' kept = []…
- Problem: What is the maximum product of positive integer parts when 10 is split into at least two parts? Run the DP. python n = 10 dp =…
- Problem: How many integer partitions does 6 have (unordered sums of positive integers equal to 6)? Run the DP. python n = 6 p = [1] + [0]…
- Problem: How many ordered pairs (x, y) with 1 <= x, y <= 10 have x y <= 10? Run the code. python print(sum(1 for x in range(1, 11) for y…