Data Structures & AlgorithmsHard

How many index pairs i < j in 1 2 3 4 5 6 8 15 satisfy A[i]·A[j] ≡ 1 (mod 7)?

  1. A. 0
  2. B. 5
  3. C. 2
  4. D. 6

Correct answer: B. 5

Values congruent mod 7 pair up as modular inverses only in special combinations (here 3 and 5, 1 and 1, 6 and 6, and so on), so test the product residue exactly. Checking the residue 6 instead of 1, the zero residue, or the sum changes the count.

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

Exams that ask this topic