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 firstname.lastname@example.org. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count all pairs of divisors of a number N whose sum is coprime with N
- Print all distinct Coprime sets possible from 1 to N
- Count of integers up to N which are non divisors and non coprime with N
- Finding a Non Transitive Coprime Triplet in a Range
- Product of all the pairs from the given array
- Minimum LCM of all pairs in a given array
- Find minimum GCD of all pairs in an array
- Find the count of even odd pairs in a given Array
- Find the GCD of LCM of all unique pairs in an Array
- Given GCD G and LCM L, find number of possible pairs (a, b)
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B
- Count Pandigital Fractions pairs in given Array
- Find the number of pairs such that their gcd is equals to 1
- Number of Co-prime pairs from 1 to N with product equals to N
- Count pairs of natural numbers with GCD equal to given number
- Queries to count the number of unordered co-prime pairs from 1 to N
- Number of Co-prime pairs obtained from the sum of digits of elements in the given range
- Maximize count of equal numbers in Array of numbers upto N by replacing pairs with their sum
- Largest number dividing maximum number of elements in the array
- Kth odd number in an array