Given two integer numbers a and b, the task is to find count of all common divisors of given numbers.
Example 1:
Input: a = 12, b = 24
Output: 6 
Explanation: all common divisors 
are 1, 2, 3, 4, 6 and 12.
Example 2:
Input: a = 3, b = 17
Output: 1
Explanation: all common divisors are 1.
Your Task:  
You dont need to read input or print anything. Complete the function commDiv() which takes n as input parameter and returns the number of common divisors.
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)
Constraints:
1<= a,b <=1000

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(sqrt(n))
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3
class Solution:
    def commDiv (self, a, b):
        # code here 

Solutions:
class Solution:

	def commDiv(self, a, b):
		sum = 0
		for i in range(1, max(a, b)):
			if a % i == 0 and b % i == 0:
				sum += 1
		return sum


class Solution:

	def commDiv(self, a, b):
		i = 1
		j = 1
		m = [1]
		p = [1]
		while True:
			s = a / i
			if a % s == 0 and (s > 1 and s == int(s)):
				m.append(s)
			g = b / j
			if b % g == 0 and (g > 1 and g == int(g)):
				p.append(g)
			if s > 1:
				i = i + 1
			if g > 1:
				j = j + 1
			if g == 1 and s == 1:
				break
		d = [x for x in m if x in p]
		return len(d)


class Solution:

	def commDiv(self, a, b):
		A = []
		if a > b:
			for i in range(1, b + 1):
				if a % i == 0 and b % i == 0:
					A.append(i)
		if b >= a:
			for i in range(1, a + 1):
				if a % i == 0 and b % i == 0:
					A.append(i)
		return len(A)


class Solution:

	def commDiv(self, a, b):
		c = 0
		if b < a:
			(a, b) = (b, a)
		i = a
		while i >= 1:
			if b % i == 0 and a % i == 0:
				c += 1
			i -= 1
		return c


class Solution:

	def commDiv(self, a, b):
		count = 0
		for i in range(1, min(a, b) + 1):
			if a % i == 0 and b % i == 0:
				count += 1
		return count


class Solution:

	def commDiv(self, a, b):
		c = 0
		for i in range(1, b + 1):
			if a % i == 0 and b % i == 0:
				c += 1
		return c


class Solution:

	def commDiv(self, a, b):
		c = max(a, b)
		if c == a:
			d = b
		else:
			d = a
		while d:
			r = c % d
			c = d
			d = r
		m = 0
		for i in range(1, c + 1):
			if a % i == 0 and b % i == 0:
				m += 1
		return m


class Solution:

	def commDiv(self, a, b):
		li1 = []
		li2 = []
		sum = 0
		for i in range(1, a + 1):
			if a % i == 0:
				li1.append(i)
		for j in range(1, b + 1):
			if b % j == 0:
				li2.append(j)
		for k in li1:
			if k in li2:
				sum = sum + 1
		return sum


class Solution:

	def commDiv(self, a, b):
		c = 0

		def gcd(a, b):
			if b == 0:
				return a
			return gcd(b, a % b)
		k = gcd(max(a, b), min(a, b))
		for h in range(1, k + 1):
			if a % h == 0 and b % h == 0:
				c += 1
		return c


class Solution:

	def commDiv(self, a, b):

		def gcd(a, b):
			r = a % b
			while r > 0:
				a = b
				b = r
				r = a % b
			return b
		if a < b:
			(a, b) = (b, a)
		(t, c) = (gcd(a, b), 1)
		lim = t ** 0.5
		for i in range(2, int(lim) + 1):
			if t % i == 0:
				c += 1
		if t == 1:
			return 1
		elif lim == int(lim):
			return 2 * c - 1
		return 2 * c


class Solution:

	def commDiv(self, a, b):
		(a, b) = sorted([a, b])
		count = 0
		for x in range(1, a + 1):
			if a % x == b % x == 0:
				count += 1
		return count


import math

class Solution:

	def commDiv(self, a, b):
		c = max(a, b)
		c = int(c)
		x = []
		for i in range(1, c):
			if a % i == 0 and b % i == 0:
				x.append(i)
		return len(x)


class Solution:

	def commDiv(self, a, b):
		import math
		count = 1
		mini = min(a, b)
		for i in range(2, mini + 1):
			if a % i == 0 and b % i == 0:
				count += 1
		return count


class Solution:

	def commDiv(self, a, b):
		import math
		ans = 0
		gcd = math.gcd(a, b)
		for i in range(1, gcd + 1):
			if gcd % i == 0:
				ans += 1
		return ans


class Solution:

	def commDiv(self, a, b):
		s = set()
		t = set()
		for i in range(1, a + 1):
			if a % i == 0:
				s.add(i)
		for i in range(1, b + 1):
			if b % i == 0:
				t.add(i)
		return len(s & t)


import math

class Solution:

	def commDiv(self, a, b):
		s = 0
		if a > b:
			(a, b) = (b, a)
		for i in range(1, a + 1):
			if a % i == 0 and b % i == 0:
				s += 1
		return s


class Solution:

	def commDiv(self, a, b):

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


class Solution:

	def commDiv(self, a, b):
		if a <= b:
			small = a
			large = b
		else:
			small = b
			large = a
		if large % small == 0:
			ctr = 1
		else:
			ctr = 0
		for i in range(1, small // 2 + 1, 1):
			if small % i == 0 and large % i == 0:
				ctr = ctr + 1
		return ctr


import math

class Solution:

	def commDiv(self, a, b):
		n = min(a, b)
		c = 0
		for i in range(1, n + 1):
			if a % i == 0 and b % i == 0:
				c += 1
		return c


class Solution:

	def commDiv(self, a, b):
		d1 = [a]
		d2 = [b]
		for x in range(1, a // 2 + 1):
			if a % x == 0:
				d1.append(x)
		for x in range(1, b // 2 + 1):
			if b % x == 0:
				d2.append(x)
		r = set(d1).intersection(d2)
		return len(r)


class Solution:

	def commDiv(self, a, b):
		i = 1
		j = 0
		while i <= a or i <= b:
			if a % i == 0 and b % i == 0:
				j += 1
			i += 1
		return j


class Solution:

	def commDiv(self, a, b):
		c = 0
		for i in range(1, max(a, b)):
			if a % i == 0 and b % i == 0:
				c += 1
		return c
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		ob = Solution()
		print(ob.commDiv(a, b))


class Solution:

	def commDiv(self, a, b):
		list = []
		for i in range(1, 1000):
			if a % i == 0 and b % i == 0:
				list.append(i)
		return len(list)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		ob = Solution()
		print(ob.commDiv(a, b))


class Solution:

	def commDiv(self, a, b):
		l = []
		k = []
		u = []
		for i in range(1, a + 1):
			if a % i == 0:
				l.append(i)
		for i in range(1, b + 1):
			if b % i == 0:
				k.append(i)
		for i in l:
			if i in k:
				u.append(i)
		return len(u)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		ob = Solution()
		print(ob.commDiv(a, b))


class Solution:

	def commDiv(self, a, b):
		c = []
		d = []
		e = []
		for i in range(1, a + 1):
			if a % i == 0:
				c.append(i)
		for j in range(1, b + 1):
			if b % j == 0:
				d.append(j)
		e = set(c).intersection(d)
		return len(e)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		ob = Solution()
		print(ob.commDiv(a, b))


class Solution:

	def commDiv(self, a, b):
		a_list = []
		b_list = []
		count = 0
		for i in range(1, a + 1):
			if a % i == 0:
				a_list.append(i)
		for i in range(1, b + 1):
			if b % i == 0:
				b_list.append(i)
		for i in a_list:
			if i in b_list:
				count += 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		ob = Solution()
		print(ob.commDiv(a, b))


class Solution:

	def commDiv(self, a, b):
		count = 0
		i = 1
		while i <= min(a, b):
			if a % i == 0 and b % i == 0:
				count = count + 1
			i = i + 1
		return count


class Solution:

	def commDiv(self, a, b):
		count = 0
		if a > b:
			for x in range(1, b + 1):
				if a % x == 0 and b % x == 0:
					count += 1
		else:
			for y in range(1, a + 1):
				if a % y == 0 and b % y == 0:
					count += 1
		return count


class Solution:

	def commDiv(self, a, b):
		c = 0
		l1 = {}
		l2 = []
		for i in range(1, a + 1):
			if a % i == 0:
				l1[i] = i
		for j in range(1, b + 1):
			if b % j == 0:
				l2.append(j)
		for k in l2:
			if l1.get(k, 0):
				c += 1
		return c


class Solution:

	def commDiv(self, a, b):
		m = min(a, b)
		c = 0
		for i in range(1, m + 1):
			if a % i == 0 and b % i == 0:
				c += 1
			else:
				continue
		return c


class Solution:

	def commDiv(self, a, b):
		l1 = []
		l2 = []
		l3 = []
		for i in range(1, a + 1):
			if a % i == 0:
				l1.append(i)
		for j in range(1, b + 1):
			if b % j == 0:
				l2.append(j)
		for i in l1:
			if i in l2:
				l3.append(i)
		return len(l3)


def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result

class Solution:

	def commDiv(self, a, b):
		j = factors(a)
		s = 0
		for i in j:
			if b % i == 0:
				s = s + 1
		return s


class Solution:

	def commDiv(self, a, b):
		c = 0
		for x in range(1, min(a, b) + 1):
			if a % x == 0 and b % x == 0:
				c += 1
		return c


class Solution:

	def commDiv(self, a, b):
		self.a = a
		self.b = b
		arr1 = []
		arr2 = []
		for i in range(1, a + 1):
			if a % i == 0:
				arr1.append(i)
		for j in range(1, b + 1):
			if b % j == 0:
				arr2.append(j)
		ans = set(arr1).intersection(set(arr2))
		return len(ans)


class Solution:

	def commDiv(self, a, b):
		list1 = [a, b]
		arr = []
		for i in range(len(list1)):
			for j in range(1, list1[i] + 1):
				if list1[i] % j == 0:
					arr.append(j)
		d = {}
		for i in arr:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		c = 0
		for (key, values) in d.items():
			if d[key] == 2:
				c += 1
		return c


import math

class Solution:

	def commDiv(self, a, b):
		(a, b) = (min(a, b), max(a, b))
		res = 0
		for i in range(1, a // 2 + 1):
			if a % i == 0 and b % i == 0:
				res += 1
		if b % a == 0:
			res += 1
		return res