Given two integer numbers, the task is to find the count of all common divisors of given numbers?
Input : a = 12, b = 24
Output: 6
Explanation: all common divisors are 1, 2, 3, 4, 6 and 12
Input : a = 3, b = 17
Output: 1
Explanation: all common divisors are 1
Input : a = 20, b = 36
Output: 3
Explanation: all common divisors are 1, 2, 4
# Python Program to find
# Common Divisors of Two Numbers
a = 12
b = 24
n = 0
for i in range(1, min(a, b)+1):
if a%i==b%i==0:
n+=1
print(n)
# Code contributed by Mohit Gupta_OMG
Output
6
Time Complexity: O(min(a, b)), Where a and b is the given number.
Auxiliary Space: O(1)
Please refer complete article on Common Divisors of Two Numbers for more details!