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?
- A. 6
- B. 8
- C. 5
- 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.
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 length 3 in the array [1, 2, 3, 1, 2, 3, 3] have all three elements distinct?
- How many contiguous subarrays of [1, 2, 3, 4, 5] have a bitwise XOR less than 4?
- How many integers x with 1 <= x <= 200 satisfy gcd(x, 180) = 1?
- What is the smallest x such that lcm(1, 2, ..., x) exceeds 1,000,000?
- How many integers x with 1 <= x <= 100 satisfy x^2 mod 24 = 1?
- How many ordered pairs (i, j) with 1 <= i, j <= 18 have i j divisible by 18?