You are viewing a single comment's thread. Return to all comments →
from math import gcd from functools import reduce
def lcm(x, y): return x * y // gcd(x, y)
def lcm_list(arr): return reduce(lcm, arr)
def gcd_list(arr): return reduce(gcd, arr)
def getTotalX(a, b): l = lcm_list(a) g = gcd_list(b)
count = 0 multiple = l while multiple <= g: if g % multiple == 0: count += 1 multiple += l return count
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 →
from math import gcd from functools import reduce
Function to compute LCM of two numbers
def lcm(x, y): return x * y // gcd(x, y)
Function to compute LCM of a list
def lcm_list(arr): return reduce(lcm, arr)
Function to compute GCD of a list
def gcd_list(arr): return reduce(gcd, arr)
def getTotalX(a, b): l = lcm_list(a) g = gcd_list(b)