Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
How many ordered pairs (a, b) with 1 <= a, b <= 6 satisfy a * b ≡ 1 (mod 7)?
- A. 6
- B. 4
- C. 36
- D. 12
Correct answer: A. 6
Every non-zero residue mod the prime 7 has exactly one inverse, so each a gives one b: 6 ordered pairs. Counting unordered pairs gives 4 ({1,1}, {2,4}, {3,5}, {6,6}), 36 counts all pairs and 12 double-counts each ordered pair.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many contiguous subarrays of [1, 1, 2, 1, 1] have all elements of the same parity?
- How many index pairs i < j in [1, 3, 4, 7, 8, 10] satisfy |a[j] - a[i]| <= 3?
- How many index triples i < j < k satisfy a[i] + a[j] + a[k] <= 4 for a = [-4, -1, 0, 2, 3, 5]?
- How many windows of length 3 in [1, 2, 3, 1, 2, 2, 4, 1, 3, 4] contain three pairwise distinct values?
- In the string "bbaacbbaaac", what is the length of the shortest contiguous substring that contains at least three letters 'a'?
- Piles of bananas are [3, 6, 7, 11] and you must finish all piles within 8 hours, eating at speed k bananas per hour (taking ceil(pile / k)…