You are viewing a single comment's thread. Return to all comments →
For python 3.x :
from math import gcd from functools import reduce
n, m = map(int, input().split()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split()))
def lcm_val(n): lcm = n[0] for i in n[1:]: lcm = lcm*i//gcd(lcm, i) return lcm
def gcd_val(m): hcf = reduce(gcd, m) return hcf
x, y = lcm_val(a), gcd_val(b) c = 0
for i in range(1, y//x + 1): if y % (x*i) == 0: c += 1
print(c)
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
For python 3.x :
from math import gcd from functools import reduce
n, m = map(int, input().split()) a = list(map(int, input().strip().split())) b = list(map(int, input().strip().split()))
def lcm_val(n): lcm = n[0] for i in n[1:]: lcm = lcm*i//gcd(lcm, i) return lcm
def gcd_val(m): hcf = reduce(gcd, m) return hcf
x, y = lcm_val(a), gcd_val(b) c = 0
for i in range(1, y//x + 1): if y % (x*i) == 0: c += 1
print(c)