Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many non-empty subsets of {1, 2, ..., 8} have a sum divisible by 4?

  1. A. 66
  2. B. 61
  3. C. 63
  4. D. 64

Correct answer: C. 63

Use a DP over remainders modulo 4 as each number is added: the counts for remainders 0..3 evolve as numbers are included. The empty subset (sum 0) must be excluded, which the total count 2ᵐ / 4 does not handle.

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

Exams that ask this topic