Data Structures & AlgorithmsModerateTCS NQT · CAT

Problem: The set S = {1, 2, 3, …, 30} is considered. How many integers in S are NOT divisible by 2, 3 or 5?

  1. A. 10
  2. B. 22
  3. C. 8
  4. D. 15

Correct answer: C. 8

The numbers 1, 7, 11, 13, 17, 19, 23, 29 avoid 2, 3, 5, so φ(30) = 8. Ignoring 5 gives 10, the complement gives 22, and 15 counts only odd numbers.

More Coding Interview Problems questions

Exams that ask this topic