Sort by

recency

|

3068 Discussions

|

  • + 0 comments

    This solution is best using the brute-force approach — it's shorter, faster, and cleaner vs LCM and GCD traditional.

    def getTotalX(a, b):
        # Write your code here
        count = 0
        for x in range(max(a), min(b) + 1):
            # Check if x is divisible by all elements in a
            if all(x % ai == 0 for ai in a):
                # Check if x divides all elements in b
                if all(bi % x == 0 for bi in b):
                    count += 1
        return count
    
  • + 0 comments

    I forgot math concepts and did this instead.

    def getTotalX(a, b):
        # Write your code here
        between = 0
        for num in range(1, max(b)+1):
            cond_a = all([bool(num%i==0) for i in a])
            cond_b = all([bool(i%num==0) for i in b])
            if cond_a and cond_b:
                between += 1
        return between
    
  • + 0 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)

    count = 0
    multiple = l
    while multiple <= g:
        if g % multiple == 0:
            count += 1
        multiple += l
    return count
    
  • + 0 comments

    The statement is very confusing. Fix it please.

  • + 0 comments
    def getTotalX(a, b):
        # Write your code here
        x = math.lcm(*a)
        y = math.gcd(*b)
        count = 0
        increment = 1
        while True:
            divider = x*increment
            if y % divider == 0:
                count += 1
            if y < divider:
                break
            increment+=1
        return count