You can calculate all the dividers a_divisorsfor an array Aas follows:
count = {}
for (i : A):
count[i]++
a_divisors = {}
for (i : range(1, 10^6)):
for (j = i * i; j <= 10^6; j += i):
if j in count.keys():
a_divisors[i] = 1
b_divisors B
:
5
3 1 4 2 8
5 2 12 8 3
:
a: 1, 2, 3, 4, 8
b: 1, 2, 3, 4, 5, 6, 8, 12
: 4
gcd(a, b) = 4, 1 A, divisor 4 1 B: 8 + 12 = 16