ORIGINAL CODING QUESTION
Coprime partner pairs
Count index pairs i<j whose positive values have greatest common divisor 1.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n integer values. Print one integer as described.
Constraints
1 ≤ n ≤ 200; 1 ≤ value ≤ 10000.
Example 1
Input
3 2 3 4
Output
2
Pairs 2,3 and 3,4 are coprime.
Example 2
Input
3 1 1 1
Output
3
Every index pair qualifies.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Equal values at different positions are still different index pairs.
Hint 2
Test gcd for each pair for a straightforward baseline.
Hint 3
Frequency counts can reduce repeated work when the value domain is small.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →