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.
Between Two Sets
Between Two Sets
Sort by
recency
|
3084 Discussions
|
Please Login in order to post a comment
Find one or more numbers x, y , z etc.. such that for x, a is a factor of x (GCD) b is a multiple of x
We need to check the numbers in the range from max(a) to min(b).
Loop through this range of integers and check numbers in 'a' divide the number without remainders. Also check x divides numbers in 'b' without remainders.
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])