Last active
May 15, 2018 23:06
-
-
Save Chillee/03529601d514ba719fe70f2404f9f206 to your computer and use it in GitHub Desktop.
Modular Multiplicative Inverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ll bin_exp(ll base, ll exp){ | |
if (exp==0) return 1; | |
return bin_exp(base*base%MOD, exp/2)*(exp%2==1 ? base : 1)%MOD; | |
} | |
ll mod_inv(ll a){ | |
return bin_exp(a, MOD-2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment