Co-prime or mutually prime pair are those pair of numbers whose GCD is 1. Given an array of size n, find number of Co-Prime or mutually prime pairs in the array.
Input : 1 2 3 Output : 3 Here, Co-prime pairs are ( 1, 2), ( 2, 3), ( 1, 3) Input :4 8 3 9 Output :4 Here, Co-prime pairs are ( 4, 3), ( 8, 3), ( 4, 9 ), ( 8, 9 )
Approach : Using two loop, check every possible pair of the array. If Gcd of the pair is 1 increment counter value and at last display it.
This article is contributed by Dibyendu Roy Chaudhuri. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Largest number less than or equal to N/2 which is coprime to N
- Count number of pairs in array having sum divisible by K | SET 2
- Composite XOR and Coprime AND
- Finding a Non Transitive Coprime Triplet in a Range
- Length of the longest increasing subsequence such that no two adjacent elements are coprime
- Count of pairs (x, y) in an array such that x < y
- Sum of Bitwise And of all pairs in a given array
- Sum of f(a[i], a[j]) over all pairs in an array of n integers
- Pairs from an array that satisfy the given condition
- Count pairs in array whose sum is divisible by K
- Count pairs in an array such that frequency of one is at least value of other
- Count of pairs in an array whose sum is a perfect square
- Making zero array by decrementing pairs of adjacent
- Count pairs in an array such that the absolute difference between them is ≥ K
- Count pairs with average present in the same array
Improved By : vt_m