Checkpoint: Pairs Divisible by D
Challenge on lesson: Checkpoint — The Residue Ledger
CHALLENGE
Difficulty: advanced+25 XP
**Bài toán.** Given n integers and a modulus d, count the pairs (i < j) with (a[i] + a[j]) divisible by d. Values may be negative. **Constraints:** 2 ≤ d ≤ 200000; 1 ≤ n ≤ 200000; |a[i]| ≤ 10^9. **Hint:** only a[i] mod d matters. Two residues r and d−r are compatible; r = 0 and (even d) r = d/2 are compatible with themselves. n² is 4·10^10 — the residue ledger is the whole point.
Press Submit to check your solution.
Back to lesson: Checkpoint — The Residue Ledger