uses xgcd instead of gcdext