Extended Euclidean Algorithm