Ext Euclid algorithm