Skip to content

Instantly share code, notes, and snippets.

@Chillee
Last active May 15, 2018 23:06
Show Gist options
  • Save Chillee/03529601d514ba719fe70f2404f9f206 to your computer and use it in GitHub Desktop.
Save Chillee/03529601d514ba719fe70f2404f9f206 to your computer and use it in GitHub Desktop.
Modular Multiplicative Inverse
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