Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B
How many index pairs i < j in the array [1, 2, 3, 4, 5, 6] satisfy gcd(a[i], a[j]) = 1 and a[i] + a[j] is odd?
- A. 9
- B. 8
- C. 15
- D. 11
Correct answer: B. 8
An odd sum needs one odd and one even element: 3 × 3 = 9 pairs, and (3, 6) is the only one with gcd > 1, leaving 8. Ignoring the gcd gives 9, ignoring the parity gives the 11 coprime pairs, and 15 counts all 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
- What is the number of elements remaining in the list after deleting each element that is smaller than the element immediately before it…
- How many NON-EMPTY subsets of [3, 6, 9, 12, 15, 4, 8, 11] (chosen by index, so equal values are different elements) have a sum divisible…
- How many subsets of {1, 2, 3, 4, 5, 6, 7, 8} have sum exactly 15? (The empty set is excluded, and each value is used at most once.)
- How many arrays of length 4 with values from {1, 2, ..., 3} have no two adjacent elements equal?
- Each step adds 1 to one element of [2, 2, 2, 5, 5, 1]. What is the minimum total number of steps so that every element becomes distinct?…
- A sorted array [1, 5, 10] is given. You may insert new positive integers into it. What is the minimum number of insertions so that every…