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)?

  1. A. 133
  2. B. 134
  3. C. 250
  4. 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

Exams that ask this topic