Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional
How many integers x with 1 <= x <= 100 are divisible by 3 and have exactly two 1-bits in their binary representation?
- A. 12
- B. 14
- C. 11
- D. 21
Correct answer: A. 12
Test both conditions for every x up to 100: exactly two set bits, and divisibility by 3. Counting all numbers with two set bits ignores the divisibility requirement, which is the trap.
More Coding Interview Problems questions
- Positive array [2, 7, 1, 8, 3, 4, 6]. What is the largest possible sum of a contiguous subarray that does not exceed 15?
- Half-open intervals [1,5), [3,8), [6,10), [9,12) are given. How many integer points x are covered by at least two of these intervals?
- Half-open intervals [0,4), [3,7), [6,9), [8,12). How many unit cells [x, x+1) are covered by two or more intervals?
- Array [2, 3, 5, 10, 2, 0, 1]. How many contiguous non-empty subarrays have a sum equal to exactly twice their maximum element?
- How many pairs of integers (x, y) with 1 <= x < y <= 12 satisfy x XOR y = x + y?
- Sorted side lengths [3, 5, 7, 9, 11, 13]. How many triples of distinct sides form a non-degenerate triangle with perimeter at most 20?