Extended Euclidean for inverting an integer mod p