def extendedGcd(a, b):
    """
    Extended Euclidean Algorithm - gcd(a,b) = a * x + b * y
        that returns x and y as well as the gcd value of the operands
    :param a: first operand
    :param b: second operand
    :return: (gcd(a,b), x, y)
    """
    res = [a, 1, 0]
    tmpRes = [b, 0, 1]
    while tmpRes[0] != 0:
        # Swap temp with res, then update temp with newly calculated div accordingly #
        div = res[0] // tmpRes[0]
        res[0], tmpRes[0] = tmpRes[0], res[0] - (div * tmpRes[0])
        res[1], tmpRes[1] = tmpRes[1], res[1] - (div * tmpRes[1])
        res[2], tmpRes[2] = tmpRes[2], res[2] - (div * tmpRes[2])
    return res