Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?

  1. A. 42
  2. B. 50
  3. C. 58
  4. D. 54

Correct answer: A. 42

Multiples of 6: 33, of 8: 25, of both (lcm 24): 8, so exactly one is 33 + 25 − 2·8 = 42. Subtracting the overlap only once gives the union 50, not subtracting it gives 58, and using 48 instead of the lcm 24 gives 33 + 25 − 4 = 54.

More Coding Interview Problems questions

Exams that ask this topic