Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?

  1. A. 41583
  2. B. 16333
  3. C. 8415
  4. D. 33168

Correct answer: D. 33168

Sum of multiples of 3 up to 500 (41583) minus multiples of 15 (8415) = 33168. 41583 skips the exclusion, subtracting multiples of 5 instead gives 16333, and 8415 is the excluded part.

More Coding Interview Problems questions

Exams that ask this topic