Implement modular inversion