Data Structures & AlgorithmsVery hard

Why is k ≥ n a necessary condition for the residues of n values modulo k to be distinct?

  1. A. Residues are always larger than the number of elements.
  2. B. Modular arithmetic only works for prime k.
  3. C. There are only k possible residues, so n distinct residues need k ≥ n.
  4. D. k must divide the sum of the values.

Correct answer: C. There are only k possible residues, so n distinct residues need k ≥ n.

Each residue lies in {0, …, k−1}, a set of exactly k values, so n pairwise distinct residues require at least n of them. The question then asks for the first such k.

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

Exams that ask this topic