Extended Euclids Algorithm