def gcd(p, q):
    p = abs(p)
    q = abs(q)

    while q != 0:
        p, q = q, p % q

    return p == 1