Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

How many integers x with 1 ≤ x ≤ 500 have a decimal digit sum divisible by 3?

  1. A. 414
  2. B. 166
  3. C. 168
  4. D. 167

Correct answer: B. 166

Digit DP on (position, digit-sum mod 3, tight). The naive count N // 3 assumes the digit sum mod 3 is evenly spread, which it is not for numbers with leading digits fixed by the bound.

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

Exams that ask this topic