Data Structures & AlgorithmsVery hardGATE CS
How many integers n with 1 <= n <= 100000 are divisible by exactly one of the numbers 6, 10 and 15?
- A. 33332
- B. 26666
- C. 23333
- D. 20000
Correct answer: C. 23333
Multiples up to 100000: 16666 of 6, 10000 of 10, 6666 of 15; every pairwise lcm is 30, so each multiple of 30 (3333 of them) lies in all three sets and none lies in exactly two. Exactly one set: 33332 - 3*3333 = 23333; the union is 26666, and plain addition of the three counts gives 33332.
More Coding Interview Problems questions
- How many primes p < 500 have p - 2 or p + 2 also prime (that is, belong to at least one twin-prime pair, counted as individual primes)?
- 0/1 knapsack with capacity 27: weights [13, 8, 9, 14, 12, 4, 11] and values [25, 19, 16, 27, 22, 8, 23] (item i has weight w[i] and value…
- How many structurally distinct binary trees with 8 nodes have at most 4 levels (a single root alone is 1 level)?
- How many binary strings of length 12 contain neither 101 nor 010 as a substring?
- What are the last three digits of 7^2025?
- In a jump game, a[i] is the maximum jump length from index i (any length from 1 to a[i] is allowed). For a = [3, 1, 4, 1, 5, 9, 2, 6, 5…