Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

What is the sum of all integers from 1 to 100 inclusive that are divisible by neither 3 nor 7?

  1. A. 2849
  2. B. 3360
  3. C. 2842
  4. D. 3367

Correct answer: C. 2842

Inclusion-exclusion on sums: subtract the multiples of 3 and of 7, then add back the multiples of 21. Subtracting the multiples of 3 alone (the last option) forgets the multiples of 7.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic