Given two integers A and B. The task is to find the count of maximum elements from the common divisors of A and B such that all selected elements are co-prime to one another.
Input: A = 12, B = 18
Common divisors of A and B are 1, 2, 3 and 6.
Select 1, 2, and 3. All the pairs are co primes to
one another i.e. gcd(1, 2) = gcd(1, 3) = gcd(2, 3) = 1.
Input: A = 1, B = 3
Approach: It can be observed that all the common factors of A and B must be a factor of their gcd. And, in order for the factors of this gcd to be co-prime to one another, one element of the pair must be either 1 or both the elements must be prime. So the answer will be 1 more than the count of prime divisors of gcd(A, B). Note that 1 is added because 1 can also be a part of the chosen divisors as its gcd with the other pairs will always be 1.
Below is the implementation of the above approach:
- Count divisors of n that have at-least one digit common with n
- Count elements in the given range which have maximum number of divisors
- Common divisors of N numbers
- Sum of common divisors of two numbers A and B
- Common Divisors of Two Numbers
- Divide the two given numbers by their common divisors
- C++ Program for Common Divisors of Two Numbers
- Java Program for Common Divisors of Two Numbers
- Count Divisors of n in O(n^1/3)
- Check if count of divisors is even or odd
- Count Divisors of Factorial
- Count of numbers below N whose sum of prime divisors is K
- C Program to Check if count of divisors is even or odd
- Count total divisors of A or B in a given range
- Count divisors of array multiplication
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.