Data Structures & AlgorithmsVery hard

For pairs i < j with (a_i + a_j) divisible by an EVEN number m, with remainder counts c_r, which formula is correct?

  1. A. Σ over all r of c_r · c_(m−r) (summing over every residue)
  2. B. c_0·(c_0−1)/2 + c_(m/2)² + Σ over r from 1 to m/2−1 of c_r·c_(m−r)
  3. C. c_0·(c_0−1)/2 + Σ over r from 1 to m/2−1 of c_r·c_(m−r) + c_(m/2)·(c_(m/2)−1)/2
  4. D. Σ over r of c_r·(c_r − 1)

Correct answer: C. c_0·(c_0−1)/2 + Σ over r from 1 to m/2−1 of c_r·c_(m−r) + c_(m/2)·(c_(m/2)−1)/2

Residues pair up as r with m−r; residue 0 and residue m/2 pair within their own class, giving C(c,2). Summing over all r counts each unordered pair twice, and squaring c_(m/2) counts ordered pairs.

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

Exams that ask this topic