Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B

How many index pairs i < j in the array [1, 2, 3, 4, 6, 7, 8, 9] have a[i] * a[j] mod 5 = 1?

  1. A. 6
  2. B. 8
  3. C. 5
  4. D. 10

Correct answer: A. 6

Bucket the values by residue mod 5; residues r and s satisfy r*s = 1 mod 5 only for the inverse pairs 1-1, 2-3 and 4-4. Forgetting that 4 is self-inverse loses pairs.

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

Exams that ask this topic