Given an integer N, the task is to count all pairs of divisors of N such that the sum of each pair is coprime with N.
Input: N = 24
There are 2 pairs (1, 24) and (2, 3) whose sum is coprime with 24
There are 4 pairs (1, 105), (3, 35), (5, 21) and (7, 15) whose sum is coprime with 105
To solve the problem mentioned above we can easily calculate the result by finding all divisors in √N complexity, and check for each pair, whether its sum is coprime with N or not.
Below is the implementation of the above approach:
Time Complexity: O(√N * log(N))
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 of integers up to N which are non divisors and non coprime with N
- Coprime divisors of a number
- Count of the non-prime divisors of a given number
- Count of Fibonacci divisors of a given number
- Count all perfect divisors of a number
- Count the numbers < N which have equal number of divisors as K
- Count of square free divisors of a given number
- Check if a number has prime count of divisors
- Count number of integers less than or equal to N which has exactly 9 divisors
- Check if count of even divisors of N is equal to count of odd divisors
- Count elements in the given range which have maximum number of divisors
- Count of elements having odd number of divisors in index range [L, R] for Q queries
- Program to find count of numbers having odd number of divisors in given range
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B
- Count number of pairs (i, j) such that arr[i] * arr[j] = arr[i] + arr[j]
- Count pairs with sum as a prime number and less than n
- Count pairs (A, B) such that A has X and B has Y number of set bits and A+B = C
- Given two arrays count all pairs whose sum is an odd number
- Count pairs with Bitwise AND as ODD number
- Find sum of divisors of all the divisors of a natural number
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : equbalzeeshan