• + 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