We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def getTotalX(a, b):
# Find LCM of all numbers in a
l = a[0]
for i in range(1, len(a)):
l = lcm(l, a[i])
# Find GCD of all numbers in b
g = b[0]
for i in range(1, len(b)):
g = math.gcd(g, b[i])
# Count numbers between sets
count = 0
for i in range(l, g + 1, l):
if g % i == 0:
count += 1
return count
Cookie support is required to access HackerRank
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 →
Python Code:
def lcm(x, y): return x * y // math.gcd(x, y)
def getTotalX(a, b): # Find LCM of all numbers in a l = a[0] for i in range(1, len(a)): l = lcm(l, a[i])