use extended GCD to compute reciprocals