Data Structures & AlgorithmsVery hardCAT · Codeforces Div2 B

How many integers x in the range 1 to 1000 are divisible by 3 and have a digit sum divisible by 7?

  1. A. 47
  2. B. 28
  3. C. 46
  4. D. 4

Correct answer: B. 28

Scan 1 to 1000, keep multiples of 3 and test the actual digit sum mod 7: 28 qualify. Testing x mod 7 instead of the digit sum gives 47 (multiples of 21), assuming the two tests are independent gives 46, and demanding that x also be a multiple of 7 gives 4.

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

Exams that ask this topic