Simple implementation of the extended euclidean algorithm