Given a number N. The task is to find the number of co-prime pairs (a, b) from 1 to N such that their product(a*b) is equal to N.
Note: A pair(a, b) is said to be co-prime if gcd(a, b) = 1.
Input: N = 120 Output: No. of co-prime pairs = 3 (3, 40) (5, 24) (8, 15) Input: N= 250 Output: No. of co-prime pairs = 3 (2, 125)
Approach: Given that the elements in the pair should be co-prime to each other. Let a co prime pair be (a, b),
Given, a * b = N.
So the idea is to run a loop from 1 to and check whether i and (N/i) are coprime to each other or not and whether, i*(N/i) = N. If yes, then count such pairs.
Below is the implementation of the above approach:
The co- prime pairs are: (3, 40) (5, 24) (8, 15) Number of coprime pairs : 3
- Count all pairs of divisors of a number N whose sum is coprime with N
- Find the number of pairs such that their gcd is equals to 1
- Number less than equals to N with maximum product of prime factors
- Number of pairs in an array having sum equal to product
- Count number of ordered pairs with Even and Odd Product
- Count of pairs in a given range with sum of their product and sum equal to their concatenated number
- Largest number less than or equal to N/2 which is coprime to N
- Partition first N natural number into two sets such that their sum is not coprime
- Product of all the pairs from the given array
- Count ordered pairs with product less than N
- Count all distinct pairs with product equal to K
- Count unordered pairs (i,j) such that product of a[i] and a[j] is power of two
- Count pairs of numbers from 1 to N with Product divisible by their Sum
- Count of pairs in an array whose product is a perfect square
- Count of pairs upto N such whose LCM is not equal to their product for Q queries
- Count of pairs in an array such that the highest power of 2 that divides their product is 1
- Maximize product of digit sum of consecutive pairs in a subsequence of length K
- Count pairs in Array whose product is a Kth power of any positive integer
- Count of index pairs in array whose range product is a positive integer
- Minimum number of squares whose sum equals to given number n
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.