• + 1 comment

    Probably, its better to use generators or maps under the all() instead of actual list comprehensions:

    def getTotalX(a, b):
        """naive, O(c(min(b) / max(a)) * (n+m)) """
        res = 0
        for i in range(max(a), min(b) + 1, max(a)):
            # print(i)
            if all(map(lambda x: i % x == 0, a)) and all(map(lambda x: x % i == 0, b)):
                res += 1
    
        return res
    

    Also, as you can see, i use max(a) as a range step, to skip "wrong" steps. p.s. I thing python will optimise max calculations when a and b are not changing.