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.
The idea is to find values x for which the following conditions apply:
x needs to be divisable by each value in a;x % a[i] == 0
each value in b needs to be divisible by x; b[j] % x ==0
In the example, a=[2,6] and b=[24,36], either 6 or 12 satisfy both conditions.
Note that x cannot be smaller than the max value in a, as the minimum divisor of a number is the number itself. Likewise, x cannot be larger than the min value in b.
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
The idea is to find values x for which the following conditions apply:
x % a[i] == 0
b[j] % x ==0
In the example,
a=[2,6]
andb=[24,36]
, either 6 or 12 satisfy both conditions. Note that x cannot be smaller than the max value in a, as the minimum divisor of a number is the number itself. Likewise, x cannot be larger than the min value in b.Python
Iterative solution:
Using list comprehension