Data Structures & AlgorithmsHardCAT · TCS NQT

Problem: The sum of all integers from 1 to 200 that are divisible by neither 4 nor 7 is what value?

  1. A. 12942
  2. B. 12158
  3. C. 7158
  4. D. 20100

Correct answer: A. 12942

20100 − 5100 (multiples of 4) − 2842 (multiples of 7) + 784 (multiples of 28) = 12942. Forgetting to add back the multiples of 28 gives 12158, 7158 is the sum of the removed numbers, and 20100 removes nothing.

More Coding Interview Problems questions

Exams that ask this topic