Data Structures & AlgorithmsModerateICPC regional · CAT · MBA placement
Problem: How many integers from 1 to 500 are coprime to 30 (share no prime factor with 30 = 2·3·5)?
- A. 133
- B. 134
- C. 250
- D. 167
Correct answer: B. 134
Inclusion-exclusion: 500 − (250 + 166 + 100) + (83 + 50 + 33) − 16 = 134. The density estimate 500 · 8/30 rounds down to 133, 250 removes only multiples of 2, and 167 forgets the factor 5.
More Coding Interview Problems questions
- Problem: What is the sum of all prime numbers less than 30?
- Problem: How many bits are needed to write 10^9 in binary (the number of bits in its binary representation)?
- Problem: Reverse the 8-bit binary representation of 13 (00001101) and report the resulting unsigned value in decimal.
- Problem: What is the smallest positive integer x such that 1 + 2 + … + x is at least 100?
- Problem: How many composite numbers lie in the range 2 to 50 (inclusive)?
- Problem: How many integers x with 0 ≤ x ≤ 99 satisfy x³ ≡ x (mod 7)?