Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: Compute the sum of the integers from 1 to 1000 that are divisible by 7 or by 11 but not by 77.

  1. A. 110110
  2. B. 104104
  3. C. 116116
  4. D. 98098

Correct answer: B. 104104

Multiples of 7 sum to 71071 and of 11 to 45045; the multiples of 77 (sum 6006) are counted in both and must be removed entirely: 71071 + 45045 − 2·6006 = 104104. Removing them once gives 110110, not removing them gives 116116, and removing them three times gives 98098.

More Coding Interview Problems questions

Exams that ask this topic