Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many pairs i < j in [2, 3, 4, 6, 9] have gcd(a[i], a[j]) = 1?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Check each of the 10 pairs with gcd. The coprime pairs are (2,3), (2,9), (3,4) and (4,9), so the count is 4.
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
- What is the sum of gcd over all contiguous subarrays of [4, 6, 8, 9]?
- How much rain water is trapped between bars of heights [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]?
- What is the maximum area of water a container can hold between two bars of heights [1, 8, 6, 2, 5, 4, 8, 3, 7] (area = min(height) times…
- What is the length of the longest palindromic substring of "forgeeksskeegfor"?
- Which string is the lexicographically smallest rotation of "bcabca"?
- With coin denominations 1, 3 and 4, what is the minimum number of coins needed to make the amount 6?