There will be two arrays of integers.  Determine all integers that satisfy the following two conditions:  

The elements of the first array are all factors of the integer being considered
The integer being considered is a factor of all elements of the second array

These numbers are referred to as being between the two arrays.  Determine how many such numbers exist.

Example 

$a=[2,6]$ 

$b=[24,36]$  

There are two numbers between the arrays: $\boldsymbol{6}$ and $12$. 

$6\%2=0$, $6\%6=0$, $24\%\textbf{6}=0$ and $36\%6=0$ for the first value. 

$12\%2=0$, $12\%6=0$ and $24\%12=0$, $36\%12=0$ for the second value.
Return $2$.

Function Description  

Complete the getTotalX function in the editor below.  It should return the number of integers that are betwen the sets.  

getTotalX has the following parameter(s):  

int a[n]: an array of integers  
int b[m]: an array of integers  

Returns  

int: the number of integers that are between the sets

Input Format

The first line contains two space-separated integers, $n$ and $m$, the number of elements in arrays $a$ and $\boldsymbol{b}$. 

The second line contains $n$ distinct space-separated integers $a[i]$ where $0\leq i<n$. 

The third line contains $m$ distinct space-separated integers $b[j]$ where $0\leq j\lt m$.

Constraints

$1\leq n,m\leq10$
$1\leq a[i]\leq100$
$1\leq b[j]\leq100$

Sample Input
2 3
2 4
16 32 96

Sample Output
3

Explanation

2 and 4 divide evenly into 4, 8, 12 and 16. 

4, 8 and 16 divide evenly into 16, 32, 96.  

4, 8 and 16 are the only three numbers for which each element of a is a factor and each is a factor of all elements of b.

Difficulty: EASY

Solutions:
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(1, 101):
	flag = True
	for j in a:
		if i % j != 0:
			flag = False
			break
	if flag:
		for k in b:
			if k % i != 0:
				flag = False
				break
	if flag:
		ans += 1
print(ans)


input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(1, 101):
	if all((i % x == 0 for x in a)) and all((x % i == 0 for x in b)):
		ans += 1
print(ans)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def commonFactors(d):
	f = []
	for i in range(1, min(d) + 1):
		if all((x % i == 0 for x in d)):
			f.append(i)
	return f
ans = 0
for i in commonFactors(b):
	if all((i % x == 0 for x in a)):
		ans += 1
print(ans)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
between = []
for i in range(1, max(b) + 1):
	if all((i % a_prime == 0 for a_prime in a)) and all((b_prime % i == 0 for b_prime in b)):
		between.append(i)
print(len(between))


import sys

def is_btwn(a, b, x):
	for t in a:
		if x % t != 0:
			return False
	for t in b:
		if t % x != 0:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
count = 0
for x in range(max(a), min(b) + 1):
	if is_btwn(a, b, x):
		count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = sorted([int(a_temp) for a_temp in input().strip().split(' ')])
b = sorted([int(b_temp) for b_temp in input().strip().split(' ')])
count = 0
ne = False
for i in range(a[len(a) - 1], b[0] + 1):
	ne = False
	for a1 in a:
		if i % a1 != 0:
			ne = True
			break
	if ne:
		continue
	for b1 in b:
		if b1 % i != 0:
			ne = True
			break
	if ne:
		continue
	count += 1
print(count)


(n, m) = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
l2 = [int(i) for i in input().split()]
sol = 0
for i in range(1, 101):
	f = 0
	for j in l1:
		if i % j != 0:
			f = 1
			break
	if f == 0:
		f2 = 0
		for k in l2:
			if k % i != 0:
				f2 = 1
				break
		if f2 == 0:
			sol += 1
print(sol)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
(max_a, min_b) = (max(a), min(b))
count = 0
for i in range(max_a, min_b + 1):
	is_factor_a = all((i % n == 0 for n in a))
	is_factor_b = all((n % i == 0 for n in b))
	if is_factor_a and is_factor_b:
		count += 1
print(count)


import sys
(len_a, len_b) = list(map(int, input().strip().split()))
a = [int(a_temp) for a_temp in input().strip().split()]
b = [int(b_temp) for b_temp in input().strip().split()]
min_b = min(b)
b_factors = []
for i in range(1, min_b + 1):
	if all([x % i == 0 for x in b]):
		b_factors.append(i)
x = []
for n in b_factors:
	if all([n % a_ == 0 for a_ in a]):
		x.append(n)
print(len(x))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort()
count = 0
for i in range(a[n - 1], b[m - 1] + 1):
	check = 1
	for j in a:
		if i % j != 0:
			check = 0
			break
	if check != 0:
		for j in b:
			if j % i != 0:
				check = 0
				break
	if check == 1:
		count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
res = 0
for v in range(1, 101, 1):
	ok = 1
	for a_temp in a:
		if v % a_temp != 0:
			ok = 0
	for b_temp in b:
		if b_temp % v != 0:
			ok = 0
	res += ok
print(res)


(_, a, b) = (input(), tuple(map(int, input().split())), tuple(map(int, input().split())))
print(sum((all((i % x == 0 for x in a)) and all((x % i == 0 for x in b)) for i in range(1, 101))))


import sys
li = []
btw = True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
for i in range(max(a), min(b) + 1):
	for n in a:
		if i % n != 0:
			btw = False
			break
		else:
			btw = True
	if btw == False:
		continue
	for n in b:
		if n % i != 0:
			btw = False
			break
		else:
			btw = True
	if btw == False:
		continue
	else:
		li.append(i)
print(len(li))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
cnt = 0
lb = len(b)
for i in range(max(a), min(b) + 1):
	for ai in a:
		if i % ai == 0:
			f = True
			for bi in b:
				if bi % i != 0:
					f = False
					break
		else:
			f = False
			break
	if f:
		cnt += 1
print(cnt)


import sys
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
bs = None
for i in range(len(b)):
	bf = factors(b[i])
	if bs is None:
		bs = set(bf)
	else:
		bs = bs & set(bf)
aset = None
bsremove = []
for bb in bs:
	for i in range(len(a)):
		if a[i] not in factors(bb):
			bsremove.append(bb)
			break
for bb in bsremove:
	bs.remove(bb)
print(len(bs))


def read_int_list():
	return [int(item) for item in input().strip().split(' ')]

def is_factor1(num):
	for x in set1:
		if num % x != 0:
			return False
	return True

def is_factor2(num):
	for x in set2:
		if x % num != 0:
			return False
	return True
input()
set1 = read_int_list()
set1.sort()
set2 = read_int_list()
set2.sort()
x1 = set1[len(set1) - 1]
x2 = set2[0]
count = 0
for num in range(x1, x2 + 1):
	if is_factor1(num) and is_factor2(num):
		count += 1
print(count)


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
min = b[0]
for x in b[1:]:
	if x < min:
		min = x
count = 0
for i in range(1, min + 1):
	flag = True
	for x in a:
		if i % x != 0:
			flag = False
			break
	if flag == True:
		for x in b:
			if x % i != 0:
				flag = False
				break
	if flag == True:
		count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
all_factors = set(range(101))

def do_stuff(i, a):
	for j in a:
		if i % j != 0:
			return False
	return True
for i in b:
	current_set = set()
	for j in range(1, i + 1):
		if i % j == 0:
			current_set.add(j)
	all_factors = all_factors.intersection(current_set)
together = 0
for i in all_factors:
	if not do_stuff(i, a):
		continue
	else:
		together += 1
print(together)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
lcm_a = a[0]
for item in a[1:]:
	lcm_a = lcm(lcm_a, item)
gcd_b = b[0]
for item in b[1:]:
	gcd_b = gcd(gcd_b, item)
if gcd_b % lcm_a != 0:
	print(0)
else:
	count = 0
	ratio = gcd_b // lcm_a
	for i in range(1, ratio + 1):
		if not ratio % i:
			count += 1
	print(count)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
low = max(a)
high = min(b)
count = 0
if high > low:
	for x in range(low, high + 1):
		flag = 0
		for i in a:
			if x % i != 0:
				flag = 1
				break
		for i in b:
			if i % x != 0:
				flag = 1
				break
		if flag == 0:
			count += 1
print(count)


(n, m) = [int(x) for x in input().split()]
an = [int(x) for x in input().split()]
am = [int(x) for x in input().split()]
maxn = max(an)
maxm = max(am)
maxnumber = max([maxm, maxn])
numbs = []
for x in range(1, maxnumber + 1):
	found = True
	for aa in an:
		if x % aa != 0:
			found = False
			break
	for bb in am:
		if bb % x != 0:
			found = False
			break
	if found:
		numbs.append(x)
print(len(numbs))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort()
count = 0
for x in range(a[-1], b[0] + 1):
	flag = True
	for i in a:
		if x % i != 0:
			flag = False
	for y in b:
		if y % x != 0:
			flag = False
	if flag == True:
		count = count + 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
lcm = 1
for i in range(len(a)):
	lcm = a[i] * lcm / gcd(a[i], lcm)
hcf = b[0]
for i in range(1, len(b)):
	hcf = gcd(b[i], hcf)
count = 0
if lcm > hcf:
	print(0)
else:
	count = 1
	i = 2
	while i * lcm <= hcf:
		if hcf % (i * lcm) == 0:
			count += 1
		i += 1
	print(count)


def fact(i, a, b):
	for aa in a:
		if i % aa != 0:
			return False
	for bb in b:
		if bb % i != 0:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
s = 0
for x in range(1, 101):
	if fact(x, a, b):
		s += 1
print(s)


import sys

def gcd(a, b):
	if b is 0:
		return a
	return gcd(b, a % b)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
lcm = a[0]
for i in range(1, n):
	lcm = a[i] * lcm // gcd(a[i], lcm)
hcf = b[0]
for i in range(1, m):
	hcf = gcd(hcf, b[i])
if hcf % lcm is not 0:
	print('0')
else:
	ans = 0
	for i in range(lcm, hcf + 1):
		if i % lcm is 0 and hcf % i is 0:
			ans = ans + 1
	print(ans)


import sys

def gcd(a, b):
	if not a:
		return b
	elif not b:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
gcd_res = 0
for n in b:
	gcd_res = gcd(gcd_res, n)
lcm_res = 1
for n in a:
	lcm_res = lcm(lcm_res, n)
res = 0
for n in range(lcm_res, gcd_res + 1, lcm_res):
	if not gcd_res % n:
		res += 1
print(res)


import sys
import math
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
factorslist = []
for i in b:
	num = 1
	factors = []
	for j in range(int(math.ceil(i / 2))):
		if i % num == 0:
			factors.append(num)
		num += 1
	factors.append(i)
	factorslist.append(factors)
intersection = list(set.intersection(*map(set, factorslist)))
count = 0
for i in intersection:
	j = 0
	while j < len(a):
		if i % a[j] != 0 or a[j] > i:
			break
		else:
			j += 1
	if j == len(a):
		count += 1
print(count)


_ = input()
a = [int(a_temp) for a_temp in input().split()]
b = [int(b_temp) for b_temp in input().split()]
possible = list(range(min(a), min(b) + 1))

def filter_between(possible, a, b):
	for num in possible:
		if all([num % x == 0 for x in a]) and all([y % num == 0 for y in b]):
			yield num
print(sum((1 for _ in filter_between(possible, a, b))))


import sys

def isMultiple(i, a):
	count = 0
	for j in a:
		if i % j == 0:
			count += 1
		else:
			break
	if count == len(a):
		return True
	else:
		return False

def isFactor(i, b):
	count = 0
	for j in b:
		if j % i == 0:
			count += 1
		else:
			break
	if count == len(b):
		return True
	else:
		return False
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
x = a[-1]
y = b[-1]
i = x
flag = True
count = 0
while i <= y and flag:
	if isMultiple(i, a) and isFactor(i, b):
		count += 1
	i += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort()
min_b = b[0]
max_a = a[-1]
res = 0
for i in range(max_a, min_b + 1):
	r1 = [i % j for j in a]
	r2 = [j % i for j in b]
	s = set(r1 + r2)
	if len(s) == 1 and 0 in s:
		res += 1
print(res)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
l = max(a)
r = min(b)
answer = 0
for i in range(l, r + 1):
	is_between = True
	for x in a:
		if i % x:
			is_between = False
			break
	for x in b:
		if x % i:
			is_between = False
			break
	if is_between:
		answer += 1
print(answer)


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
dummy = input()
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
factor_set_B = factors(B[0])
for num in B[1:]:
	factor_set_B = set.intersection(factor_set_B, factors(num))
print(len({x for x in factor_set_B if all((x % n == 0 for n in A))}))


import sys

def hcf(a, b):
	if a % b == 0:
		return b
	else:
		return hcf(b, a % b)

def lcm(a, n):
	res = 1
	for i in range(0, n):
		res = res * a[i] // hcf(res, a[i])
	return res
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
l = lcm(a, n)
h = b[0]
for i in range(0, m - 1):
	h = hcf(b[i], b[i + 1])
	b[i + 1] = h
number = 0
for i in range(l, h + 1):
	if h % i == 0 and i % l == 0:
		number += 1
print(number)


import sys
(n, m) = input().strip().split(' ')
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def my_gcd(x, y):
	if x == 0:
		return y
	if y == 0:
		return x
	return my_gcd(y % x, x)

def my_lcm(x, y):
	return x * y // my_gcd(x, y)
lcm = 1
for i in a:
	lcm = my_lcm(lcm, i)
gcd = 0
for i in b:
	gcd = my_gcd(gcd, i)
ans = 0
x = lcm
while lcm <= gcd:
	if gcd % lcm == 0:
		ans += 1
	lcm += x
print(ans)


import sys
from functools import reduce

def gcd(x, y):
	if x % y == 0:
		return y
	else:
		return gcd(y, x % y)

def lcm(a, b):
	return a * b // gcd(a, b)

def lcmm(*args):
	return reduce(lcm, args)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
minb = b[0]
for i in b:
	if minb > i:
		minb = i
gcdb = b[0]
for i in range(1, len(b)):
	gcdb = gcd(gcdb, b[i])
lcma = lcmm(*a)
result = 0
tmp = lcma
while lcma <= gcdb:
	if gcdb % lcma == 0:
		result += 1
	lcma += tmp
print(result)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
max_a = max(a)
min_b = min(b)
count = max_a - 1
result = 0
boo = True
while count <= min_b:
	count += 1
	boo = True
	for i in a:
		if count % i != 0:
			boo = False
			break
	if not boo:
		continue
	for i in b:
		if i % count != 0:
			boo = False
			break
	if not boo:
		continue
	result += 1
print(result)


def gcd(a, b):
	if a == 0:
		return b
	else:
		return gcd(b % a, a)

def lcs(a, b):
	return a * b // gcd(a, b)
(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
begin = a[0]
for i in range(1, len(a)):
	begin = lcs(begin, a[i])
end = b[0]
for i in range(1, len(b)):
	end = gcd(end, b[i])
result = 0
middle = begin
while middle <= end:
	if end % middle == 0:
		result += 1
	middle += begin
print(result)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
A = [int(a_temp) for a_temp in input().strip().split(' ')]
B = [int(b_temp) for b_temp in input().strip().split(' ')]
res = 0
for x in range(1, 101):
	acond = True
	for a in A:
		if x % a != 0:
			acond = False
			break
	bcond = True
	if acond:
		for b in B:
			if b % x != 0:
				bcond = False
				break
	if acond and bcond:
		res += 1
print(res)


(n, m) = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = set()
D = set()
for i in range(max(A), min(B) + 1):
	k = 0
	for j in A:
		if i % j != 0:
			k += 1
	if k == 0:
		C.add(i)
for i in C:
	k = 0
	for j in B:
		if j % i != 0:
			k += 1
			D.add(i)
			break
print(len(C - D))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort()
c = [i for i in range(1, 101)]
for x in a:
	c = list(filter(lambda y: y % x == 0, c))
for x in b:
	c = list(filter(lambda y: x % y == 0, c))
print(len(c))


import sys

def isFactorA(x, a):
	for x_a in a:
		if x % x_a != 0:
			return False
	return True

def isFactorB(x, b):
	for x_b in b:
		if x_b % x != 0:
			return False
	return True

def findNumbersBetweenTwoSets(a, b):
	maxA = max(a)
	minB = min(b)
	if maxA > minB:
		return 0
	nBetweens = 0
	for x in range(maxA, minB + 1, maxA):
		if isFactorA(x, a) and isFactorB(x, b):
			nBetweens += 1
	return nBetweens
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
print(findNumbersBetweenTwoSets(a, b))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
final_list = []
for i in range(a[n - 1], b[0] + 1):
	L = [1 for j in a if i % j == 0]
	if len(L) != len(a):
		pass
	else:
		L1 = [1 for k in b if k % i == 0]
		if len(L1) == len(b):
			final_list.append(i)
		else:
			pass
print(len(final_list))


import sys

def is_valid(x, a, b):
	for i in a:
		if x % i != 0:
			return False
	for i in b:
		if i % x != 0:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
maxa = max(a)
minb = min(b)
counter = 0
for i in range(maxa, minb + 1):
	if is_valid(i, a, b):
		counter += 1
print(counter)


import sys

def check_a(x, a):
	for n in a:
		if x % n != 0:
			return False
	return True

def check_b(x, b):
	for n in b:
		if n % x != 0:
			return False
	return True

def check(x, a, b):
	return check_a(x, a) and check_b(x, b)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
count = 0
for x in range(max(a), max(b) + 1):
	if check(x, a, b):
		count += 1
print(count)


import sys
lst = []
lst1 = []
temp = 0
temp1 = 0
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
k = 0
for i in range(a[n - 1], b[n - 2] + 1):
	for j in range(m):
		if b[j] % i == 0:
			temp = temp + 1
		if temp == m:
			lst.append(i)
			temp = 0
	temp = 0
for i in range(a[n - 1], b[n - 2] + 1):
	for j in range(n):
		if i % a[j] == 0:
			temp1 = temp1 + 1
		if temp1 == n:
			lst1.append(i)
			temp1 = 0
	temp1 = 0
print(len(set(lst).intersection(lst1)))


from functools import reduce
from collections import deque
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def gcd_two(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def gcd(nums):
	return reduce(lambda x, y: gcd_two(x, y), nums)

def lcm(nums):
	return reduce(lambda x, y: x * y / gcd_two(x, y), nums)

def between(xs, ys):
	minn = lcm(xs)
	maxn = gcd(ys)
	betweens = deque()
	iterator = maxn
	while iterator >= minn:
		if not iterator % minn and (not maxn % iterator):
			betweens.appendleft(iterator)
		iterator -= minn
	return betweens
print(len(between(a, b)))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
sum_el = 0
for i in range(max(a), max(b) + 1):
	flag1 = True
	flag2 = True
	for a_i in a:
		if i % a_i == 0:
			pass
		else:
			flag1 = False
			break
	for b_i in b:
		if b_i % i == 0:
			pass
		else:
			flag2 = False
			break
	if flag1 and flag2:
		sum_el += 1
print(sum_el)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
c = a.copy()
c.extend(b)
c.extend(range(a[n - 1] + 1, b[0]))
count = 0
for x in c:
	allFactors = all((x % z == 0 for z in a))
	if allFactors == False:
		continue
	allFactors = all((z % x == 0 for z in b))
	if allFactors == False:
		continue
	count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]

def is_after(x):
	for aa in a:
		if x % aa != 0:
			return False
	return True

def is_before(x):
	for bb in b:
		if bb % x != 0:
			return False
	return True
candidates = [x for x in range(1, 101) if is_after(x) and is_before(x)]
print(len(candidates))


import math
import functools

def primes_less_than(n):
	primes = [x for x in (2, 3, 5, 7, 11, 13) if x < n]
	if n <= 17:
		return primes
	candidates = [x for x in range(n - 2 | 1, 15, -2) if x % 3 and x % 5 and x % 7 and x % 11 and x % 13]
	top = int(math.ceil(n ** 0.5))
	while True:
		p = candidates.pop()
		primes.append(p)
		if p > top:
			break
		candidates = list(filter(p.__rmod__, candidates))
	candidates.reverse()
	primes.extend(candidates)
	return primes

def prime_factorize(n, primes):
	f = {}
	while n > 1:
		for p in primes:
			if n % p == 0:
				n = n // p
				try:
					f[p] += 1
				except KeyError:
					f[p] = 1
	return f

def gcd(l):
	if len(l) > 2:
		return functools.reduce(lambda x, y: gcd([x, y]), l)
	elif len(l) == 2:
		if l[1] == 0:
			return l[0]
		else:
			return gcd([l[1], l[0] % l[1]])
	else:
		return l[0]
(n, m) = map(int, input().strip().split(' '))
a = set((int(a_tmp) for a_tmp in input().strip().split(' ')))
b = [int(b_tmp) for b_tmp in input().strip().split(' ')]
if max(a) > max(b):
	print(0)
else:
	primes = primes_less_than(max(b) + 1)
	f_a = {}
	for x in a:
		y = prime_factorize(x, primes)
		for k in y.keys():
			try:
				if y[k] > f_a[k]:
					f_a[k] = y[k]
			except KeyError:
				f_a[k] = y[k]
	f_b = prime_factorize(gcd(b), primes)
	x = 1
	e = 0
	for k in f_a.keys():
		try:
			if f_b[k] >= f_a[k]:
				x *= f_b[k] - f_a[k] + 1
			else:
				e = 1
				break
		except KeyError:
			e = 1
			break
	if e == 1:
		print(0)
	else:
		for k in f_b.keys():
			if k not in f_a.keys():
				x *= f_b[k] + 1
		print(x)


import sys
import functools

def between_count(set1, set2):
	return len(between(set1, set2))

def between(set1, set2):
	x = lcm_all(set1)
	min_b = min(set2)
	max_k = min_b // x
	result = []
	for k in range(1, max_k + 1):
		x_k = x * k
		if is_factor_of_all(x_k, set2):
			result.append(x_k)
	return result

def lcm_all(iterable):
	return functools.reduce(lcm, iterable)

def lcm(a, b):
	return int(abs(a) / gcd(a, b) * abs(b))

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return int(a)

def is_factor_of_all(factor, products):
	for product in products:
		if product < factor:
			return False
		if product % factor != 0:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
print(between_count(a, b))


import sys

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def count(number):
	L = list()
	for p in prime:
		count = 1
		while True:
			if number % p == 0:
				number = number // p
				count += 1
			else:
				L.append(count)
				break
		if number == 1:
			break
	ans = 1
	for l in L:
		ans *= l
	return ans
prime = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort(reverse=True)
b.sort(reverse=True)
if m == 1:
	factor = b[0]
elif m == 2:
	factor = gcd(b[0], b[1])
else:
	factor = gcd(b[0], b[1])
	for i in range(2, m):
		factor = gcd(b[i], factor)
if n == 1:
	num = a[0]
elif n == 2:
	num = lcm(a[0], a[1])
else:
	num = lcm(a[0], a[1])
	for i in range(2, n):
		num = lcm(num, a[i])
num = int(num)
if factor % num == 0:
	ans = 0
	for i in range(num, factor + 1):
		if i % num == 0 and factor % i == 0:
			ans += 1
	print(ans)
else:
	print(0)


import sys

def isBetween(n):
	for i in a:
		if n % i != 0:
			return False
	for i in b:
		if i % n != 0:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a = sorted(a)
b = sorted(b)
result = 0
i = 1
while a[-1] * i <= b[0]:
	if isBetween(a[-1] * i):
		result += 1
	i += 1
print(result)


import sys

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort()
maxi = b[0]
count = 0
lc = a[0]
for i in range(1, n):
	lc = lcm(lc, a[i])
for i in range(lc, maxi + 1, lc):
	for j in range(m):
		if b[j] % i != 0:
			break
	else:
		count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
answer = 0

def fact(x, factors):
	for factor in factors:
		if x % factor != 0:
			return False
	return True

def mult(x, multiples):
	for multiple in multiples:
		if multiple % x != 0:
			return False
	return True
for x in range(max(a), min(b) + 1):
	if fact(x, a) and mult(x, b):
		answer += 1
print(answer)


import sys

def isGoodA(n, nums):
	for num in nums:
		if 0 != n % num:
			return False
	return True

def isGoodB(n, nums):
	for num in nums:
		if 0 != num % n:
			return False
	return True
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
count = 0
for n in range(max(a), min(b) + 1):
	if isGoodA(n, a) and isGoodB(n, b):
		count += 1
print(count)


import sys

def check_factors(a, start):
	count = 0
	for elem in a:
		if start % elem == 0:
			count += 1
	if count == len(a):
		return True
	else:
		return False

def check_if_factors(b, end):
	count = 0
	for elem in b:
		if elem % end == 0:
			count += 1
	if count == len(b):
		return True
	else:
		return False
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
start = 0
end = -1
a = []
b = []
for a_temp in input().strip().split(' '):
	a_temp = int(a_temp)
	if start < a_temp:
		start = a_temp
	a.append(a_temp)
for b_temp in input().strip().split(' '):
	b_temp = int(b_temp)
	if end == -1:
		end = b_temp
	elif end > b_temp:
		end = b_temp
	b.append(b_temp)
result_count = 0
while start <= end:
	if check_factors(a, start) and check_if_factors(b, start):
		result_count += 1
	start += 1
print(result_count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
(max_a, min_b) = (max(a), min(b))
if max_a > min_b:
	print(0)
else:
	count = 0
	for i in range(max_a, min_b + 1):
		c = True
		for k in a:
			if i % k != 0:
				c = False
				break
		if c:
			for k in b:
				if k % i != 0:
					c = False
					break
		if c:
			count += 1
	print(count)


import sys
from functools import reduce

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)

def lcmm(args):
	return reduce(lcm, args)
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
s = sorted(b)
p = lcmm(a)
q = p
t = 0
for i in range(p, s[0] + 1, q):
	r = 10
	for j in range(0, m):
		if s[j] % i == 0:
			continue
		else:
			r = 0
			break
	if r == 10:
		t = t + 1
print(t)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
ab = []
ans = 0
l = False
f = False
for i in range(max(a), min(b) + 1):
	for j in a:
		if i % j != 0:
			l = False
			break
		else:
			l = True
	for h in b:
		if h % i != 0:
			f = False
			break
		else:
			f = True
	if l == True and f == True:
		ans += 1
print(ans)


import sys

def factors(n):
	return set((x for tup in ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0) for x in tup))
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
factorSetList = []
for i in b:
	factorSetList.append(factors(i))
common_factors = set.intersection(*factorSetList)
answer = 0
for i in common_factors:
	if len(set(a).difference(factors(i))) == 0:
		answer += 1
print(answer)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
A = [int(a_temp) for a_temp in input().strip().split(' ')]
B = [int(b_temp) for b_temp in input().strip().split(' ')]
ans = 0
for i in range(1, 101):
	good = True
	for a in A:
		if i < a:
			good = False
			break
		if i % a != 0:
			good = False
			break
	if not good:
		continue
	for b in B:
		if i > b:
			good = False
			break
		if b % i != 0:
			good = False
			break
	if good:
		ans += 1
print(ans)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
x = max(a)
no_of_x = 0
while x <= min(b):
	i = 0
	j = 0
	while i in range(n):
		if x % a[i] == 0:
			j += 1
		i += 1
	k = 0
	p = 0
	while k in range(m):
		if b[k] % x == 0:
			p += 1
		k += 1
	if j == n and p == m:
		no_of_x += 1
	x += 1
print(no_of_x)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
num = 0
for i in range(max(a), min(b) + 1):
	if all((i % j == 0 for j in a)) and all((k % i == 0 for k in b)):
		num += 1
print(num)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
aset = [int(a_temp) for a_temp in input().strip().split(' ')]
bset = [int(b_temp) for b_temp in input().strip().split(' ')]
numtest = list(range(1, 101))
num = 0
for i in numtest:
	inst = True
	for a in aset:
		if i % a != 0:
			inst = False
		else:
			for b in bset:
				if b % i != 0:
					inst = False
	if inst:
		num += 1
print(num)


import sys

def main():
	(n, m) = input().strip().split(' ')
	(n, m) = [int(n), int(m)]
	a = [int(a_temp) for a_temp in input().strip().split(' ')]
	b = [int(b_temp) for b_temp in input().strip().split(' ')]
	result = 0
	for i in range(max(a), min(b) + 1):
		test = 0
		for a_i in a:
			if i % a_i != 0:
				test = 1
				break
		if test == 0:
			for b_i in b:
				if b_i % i != 0:
					test = 1
					break
		if test == 0:
			result += 1
	print(result)
main()


import sys
arr1 = input().split()
n = int(arr1[0])
m = int(arr1[1])
a = input().split()
b = input().split()
ans = 0

def check_a(i):
	flag = True
	for j in range(n):
		if i % int(a[j]) != 0:
			flag = False
	return flag

def check_b(i):
	flag = True
	for j in range(m):
		if int(b[j]) % i != 0:
			flag = False
	return flag
for i in range(1, 101):
	if check_a(i):
		if check_b(i):
			ans += 1
print(ans)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
max_b = max(b)
r = 0
for num in range(1, max_b + 1):
	found = True
	for a_ in a:
		if num % a_ != 0:
			found = False
			break
	for b_ in b:
		if b_ % num != 0:
			found = False
			break
	if found:
		r += 1
print(r)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
output = 0
for i in range(a[n - 1], b[0] + 1):
	count = 0
	for j in range(0, n):
		if i % a[j] == 0:
			count = count + 1
	for k in range(0, m):
		if b[k] % i == 0:
			count = count + 1
	if count == n + m:
		output = output + 1
print(output)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a.sort()
b.sort(reverse=True)
st = a[-1]
en = b[0]
c = 0
for x in range(st, en + 1):
	flag = True
	for j in a:
		if x % j != 0:
			flag = False
			break
	if not flag:
		continue
	for j in b:
		if j % x != 0:
			flag = False
			break
	if flag:
		c += 1
print(c)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
a = sorted(a)
b = sorted(b)
a_n = a[len(a) - 1]
b_n = b[0]
max_n = 0
min_n = 0
if a_n > b_n:
	min_n = b_n
	max_n = a_n
else:
	min_n = a_n
	max_n = b_n
ans = set()
for i in range(min_n, max_n + 1):
	flag = True
	for j in a:
		if i % j != 0:
			flag = False
			break
	if not flag:
		continue
	flag = True
	for j in b:
		if j % i != 0:
			flag = False
			break
	if flag:
		ans.add(i)
print(len(ans))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
low = max(a)
high = min(b)
count = 0
for x in range(low, high + 1):
	between = True
	for y in a:
		if x % y != 0:
			between = False
			break
	for z in b:
		if z % x != 0:
			between = False
			break
	if between:
		count += 1
print(count)


from itertools import *
from operator import *
from functools import *
(n, m) = map(int, input().split())
(*A,) = map(int, input().split())
(*B,) = map(int, input().split())
print(sum([not any(map(partial(reduce, mod), list(product([x], A)) + list(product(B, [x])))) for x in range(1, 200)]))


def gcd(a, b):
	while max(a, b) % min(a, b) != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	return min(a, b)

def lcmt(a, b):
	return int(a * b / gcd(a, b))

def lcm(l):
	if len(l) == 1:
		return l[0]
	lc = lcmt(l[0], l[1])
	for i in range(2, len(l)):
		lc = lcmt(lc, l[i])
	return lc
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
lc = lcm(a)
bmin = min(b)
c = []
(x, i) = (lc, 1)
while x * i <= bmin:
	if bmin % (x * i) == 0:
		c.append(x * i)
	i += 1
tot = 0
for i in c:
	for j in b:
		if j % i != 0:
			break
	else:
		tot += 1
print(tot)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
x = 1
c = 0
while x <= max(b):
	c1 = 0
	c2 = 0
	for y in a:
		if x % y == 0:
			c1 = c1 + 1
	for z in b:
		if z % x == 0:
			c2 = c2 + 1
	if c1 == len(a) and c2 == len(b):
		c = c + 1
	x = x + 1
print(c)


from functools import reduce

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def lcm(a, b):
	return a * b // gcd(a, b)
[la, lb] = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
l = reduce(lcm, a, 1)
g = reduce(gcd, b, b[0])
print(len(list(filter(lambda x: g % x == 0, range(l, g + 1, l)))))


import sys

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def lcm(a, b):
	return a * b // gcd(a, b)

def GCD(a):
	for i in range(1, len(a)):
		if i == 1:
			g = gcd(a[i - 1], a[i])
		else:
			g = gcd(g, a[i])
	return g

def LCM(a):
	for i in range(1, len(a)):
		if i == 1:
			l = lcm(a[i - 1], a[i])
		else:
			l = lcm(l, a[i])
	return l
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
if len(a) > 1:
	l = LCM(a)
else:
	l = a[0]
if len(b) > 1:
	g = GCD(b)
else:
	g = b[0]
count = 0
for i in range(1, g // l + 1):
	if g % (l * i) == 0:
		count += 1
print(count)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x_set = set()
for x in range(a[0], b[0] + 1):
	if b[0] % x == 0 and x % a[0] == 0:
		x_set.add(x)
for i in range(n):
	for j in range(m):
		if i == j == 0:
			continue
		for x in list(x_set):
			if b[j] % x != 0 or x % a[i] != 0:
				x_set.remove(x)
print(len(x_set))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
l = []
c = [max(a), max(b)]
d = max(c)
for i in range(1, d + 1):
	f = 0
	for j in a:
		if i % j != 0:
			f = 1
	if f == 0:
		l.append(i)
k = []
for i in l:
	f = 0
	for j in b:
		if j % i != 0:
			f = 1
	if f == 0:
		k.append(i)
for i in range(len(k)):
	if k.count(i) > 1:
		pop(i)
		k.append(i)
print(len(k))


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
count = 0
start = max(a)
end = min(b)
for i in range(start, end + 1):
	for element in b:
		if element % i != 0:
			break
	else:
		for element in a:
			if i % element != 0:
				break
		else:
			count = count + 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
res = 0
for x in range(max(a), min(b) + 1):
	c1 = True
	c2 = True
	for i in a:
		if x % i != 0:
			c1 = False
			break
	for i in b:
		if i % x != 0:
			c2 = False
			break
	if c1 and c2:
		res += 1
print(res)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
LIST = []
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
last = min(b)
first = max(a)
firstlen = len(a)
lastlen = len(b)
for x in range(first, last + 1):
	c = 0
	for y in b:
		if y % x == 0:
			c = c + 1
	if c == lastlen:
		LIST.append(x)
p = 0
for w in LIST:
	c = 0
	for z in a:
		if w % z == 0:
			c = c + 1
	if c == firstlen:
		p = p + 1
print(p)


(len_A, len_B) = [int(i) for i in input().strip().split(' ')]
A = [int(a) for a in input().strip().split(' ')]
B = [int(b) for b in input().strip().split(' ')]
between = []
for x in range(max(A), min(B) + 1):
	first_condition = True
	second_condition = True
	for a in A:
		if x % a != 0:
			first_condition = False
			break
	if first_condition:
		for b in B:
			if b % x != 0:
				second_condition = False
		if second_condition:
			between.append(x)
print(len(between))


import sys
limit = 100
(n, m) = tuple((int(x) for x in sys.stdin.readline().split()))
a = tuple((int(x) for x in sys.stdin.readline().split()))
b = tuple((int(x) for x in sys.stdin.readline().split()))
solution = 0
for i in range(1, limit + 1):
	ok = True
	for j in a:
		if i % j != 0:
			ok = False
			break
	for j in b:
		if j % i != 0:
			ok = False
			break
	if ok:
		solution += 1
print(solution)


import sys

def hcf(x, y):
	u = max(x, y)
	v = min(x, y)
	while v > 0:
		(u, v) = (v, u % v)
	return u
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
num_between = 0
max_a = 0
for i in range(n):
	max_a = max(max_a, a[i])
hcf_b = b[0]
for i in range(1, m):
	hcf_b = hcf(hcf_b, b[i])
for i in range(max_a, hcf_b + 1, max_a):
	if hcf_b % i == 0:
		is_a_mult = True
		for j in range(n):
			is_a_mult = is_a_mult and i % a[j] == 0
		num_between += is_a_mult
print(num_between)


def is_between(x):
	if x == 1:
		return True
	for i in a:
		if x % i != 0:
			return False
	for i in b:
		if i % x != 0:
			return False
	return True
(l1, l2) = input().strip().split()
(l1, l2) = (int(l1), int(l2))
a_str = input()
a = list(map(int, a_str.split()))
a = a[:l1]
b_str = input()
b = list(map(int, b_str.split()))
b = b[:l2]
count = 0
for i in range(max(a), max(b) + 1):
	if is_between(i):
		count = count + 1
print(count)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
count = 0
for i in range(max(a), min(b) + 1):
	ls = []
	for number in a:
		ls.append(i % number)
	for number in b:
		ls.append(number % i)
	if sum(ls) == 0:
		count += 1
print(count)


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
start = max(a)
end = max(b)
count = 0
for i in range(start, end + 1, start):
	list1 = [i % x for x in a]
	list2 = [x % i for x in b]
	if max(list1) == min(list1) == max(list2) == min(list2) == 0:
		count += 1
print(count)


(n, m) = map(int, input().split())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
ans = 0
x = max(a) - 1
while x <= min(b):
	x += 1
	if len(list(filter(lambda y: y % x, b)) + list(filter(lambda y: x % y, a))):
		continue
	ans += 1
print(ans)


import sys

def g(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def l(x, y):
	lcm = x * y // g(x, y)
	return lcm
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
lcm = a[0]
for i in a:
	lcm = l(lcm, i)
gcd = b[0]
for j in b:
	gcd = g(gcd, j)
counter = 0
for k in range(lcm, gcd + 1):
	if gcd % k == 0 and k % lcm == 0:
		counter += 1
print(counter)


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = [int(a_temp) for a_temp in input().strip().split(' ')]
b = [int(b_temp) for b_temp in input().strip().split(' ')]
counter = 0
for i in range(1, min(b) + 1):
	if all((i % j == 0 for j in a)) and all((j % i == 0 for j in b)):
		counter += 1
print(counter)