Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code.

Problem: How many integers in [1, 100000] are multiples of 7 whose last digit is 3? Run the code.
print(sum(1 for x in range(1, 100001) if x % 7 == 0 and x % 10 == 3))
What is printed?
  1. A. 14285
  2. B. 1428
  3. C. 10000
  4. D. 1429

Correct answer: B. 1428

A multiple of 7 ends in 3 exactly when x ≡ 63 (mod 70), so the count is floor((100000 − 63)/70) + 1 = 1428. 14285 counts all multiples of 7, 10000 all numbers ending in 3, and rounding 100000/70 up gives 1429.

More Coding Interview Problems questions

Exams that ask this topic