luoheng
9/6/2019 - 7:25 AM

CommonPrimeDivisors

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def gcd(a, b):
    if a < b:
        a, b = b, a
    if a % b == 0:
        return b
    return gcd(b, a % b)

def check(a, b):
    if a < b:
        a, b = b, a
    c = a
    while c != 1:
        div = gcd(c, b)
        if div == 1:
            return False
        c //= div
    c = b
    while c != 1:
        div = gcd(a, c)
        if div == 1:
            return False
        c //= div
    return True

def solution(A, B):
    # write your code in Python 3.6
    return sum(1 for i in range(len(A)) if check(A[i], B[i]))