Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code.

Problem: How many integers in [1, 500] are multiples of 3 but not of 5? Run the code.
print(sum(1 for x in range(1, 501) if x % 3 == 0 and x % 5 != 0))
What is printed?
  1. A. 166
  2. B. 100
  3. C. 167
  4. D. 133

Correct answer: D. 133

Multiples of 3 number 166 and of 15 number 33, so 166 - 33 = 133.

More Coding Interview Problems questions

Exams that ask this topic