Given two numbers, A and B. Find the number of common divisors of A and B. 
 
Example 1:
Ã¢â¬â¹Input : A = 2 and B = 4
Output : 2
Explanation:
There are only two common divisor of 2 and 4.
That is 1 and 2.
Ã¢â¬â¹Example 2:
Input : A = 3 and B = 5 
Output :  1
 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function common_divisor() that takes an integer A, another integer B, and return the number of the common divisor of A and B. The driver code takes care of the printing.
Expected Time Complexity: O(SQRT(min(A,B))).
Expected Auxiliary Space: O(1).
 
Constraints:
1 ≤ A, B ≤ 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Starter code: #User function Template for python3



def common_divisor (n, m) : 

    #Complete the function

  

Solutions:
def common_divisor(n, m):
	c = 0
	for i in range(1, m + 1):
		if n % i == 0 and m % i == 0:
			c += 1
	return c


def common_divisor(n, m):
	x = min(n, m)
	lis = [i for i in range(1, x + 1) if n % i == 0 and m % i == 0]
	return len(lis)


def common_divisor(n, m):
	count = 0
	if n > m:
		a = n
	else:
		a = m
	for i in range(1, a + 1):
		if n % i == 0 and m % i == 0:
			count += 1
	return count


def common_divisor(n, m):
	import math
	ans = 0
	gcd = math.gcd(n, m)
	for i in range(1, gcd + 1):
		if (n % i == 0) & (m % i == 0):
			ans += 1
	return ans


import math

def common_divisor(n, m):
	(m, n) = (min(m, n), max(m, n))
	result = 0
	i = 1
	while i <= math.sqrt(m):
		if n % i == 0 and m % i == 0:
			result += 1
		if n % (m // i) == 0 and m % (m // i) == 0 and (i != m // i):
			result += 1
		i += 1
	return result


def gcd(n, m):
	if m > n:
		temp = n
		n = m
		m = temp
	if n == 0:
		return m
	if m == 0:
		return n
	return gcd(m, n % m)

def common_divisor(n, m):
	x = gcd(n, m)
	sm = 0
	for i in range(1, x + 1):
		if x % i == 0:
			sm += 1
	return sm


from math import sqrt

def common_divisor(n, m):

	def gcd(a, b):
		if a == 0:
			return b
		return gcd(b % a, a)
	c = 0
	n = gcd(n, m)
	x = int(sqrt(n))
	for i in range(1, x + 1):
		if n % i == 0:
			if n / i == i:
				c += 1
			else:
				c += 2
	return c


def common_divisor(n, m):
	count = 0
	s = min(m, n) + 1
	for i in range(1, s):
		if n % i == 0 and m % i == 0:
			count = count + 1
	return count


def greatest_divisor(n, m):
	if m == 0:
		return n
	return greatest_divisor(m, n % m)

def common_divisor(n, m):
	c = 0
	g_divisior = greatest_divisor(n, m)
	r = int(g_divisior ** (1 / 2))
	for i in range(1, r + 1):
		if g_divisior % i == 0:
			c += 2
		if i * i == g_divisior:
			c -= 1
	return c


def common_divisor(n, m):
	l = []
	k = []
	ans = []
	for i in range(1, min(n, m) + 1):
		if n % i == 0 and m % i == 0:
			l.append(i)
	return len(l)


def common_divisor(n, m):
	result = 0
	if m < n:
		d = m
	else:
		d = n
	for i in range(1, d + 1):
		if n % i == 0 and m % i == 0:
			result += 1
	return result


def common_divisor(n, m):
	c = 0
	if n < m:
		a = n
	else:
		a = m
	for i in range(1, a + 1):
		if n % i == 0 and m % i == 0:
			c += 1
		else:
			pass
	return c