functions for calculating the greatest common divisor of two integers or their least common multiple computes the greatest common divisor of integers a and b using euclid s algorithm gcd gcd gcd gcd see proof https proofwiki orgwikigcdfornegativeintegers computes the lowest common multiple of integers a and b return absa absb gcda b def trailingzerox count 0 while x and not x 1 count 1 x 1 return count def gcdbita b computes the greatest common divisor of integers a and b using euclid s algorithm gcd 𝑎 𝑏 gcd 𝑎 𝑏 gcd 𝑎 𝑏 gcd 𝑎 𝑏 see proof https proofwiki org wiki gcd_for_negative_integers computes the lowest common multiple of integers a and b given a positive integer x computes the number of trailing zero of x example input 34 100010 output 1 input 40 101000 output 3 given two non negative integer a and b computes the greatest common divisor of a and b using bitwise operator similar to gcd but uses bitwise operators and less error handling
def gcd(a, b):
    
    a_int = isinstance(a, int)
    b_int = isinstance(b, int)
    a = abs(a)
    b = abs(b)
    if not(a_int or b_int):
        raise ValueError("Input arguments are not integers")

    if (a == 0) or (b == 0) :
        raise ValueError("One or more input arguments equals zero")

    while b != 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    
    return abs(a) * abs(b) / gcd(a, b)


def trailing_zero(x):
    count = 0
    while x and not x & 1:
        count += 1
        x >>= 1
    return count


def gcd_bit(a, b):
    
    tza = trailing_zero(a)
    tzb = trailing_zero(b)
    a >>= tza
    b >>= tzb
    while b:
        if a < b:
            a, b = b, a
        a -= b
        a >>= trailing_zero(a)
    return a << min(tza, tzb)