Morass

Inverze

Apr 9th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #define MOD (1000000007)
  2. ll gcdE(ll a,ll m,ll &x,ll &y){
  3.     if(!a)return x=0,y=1,m;
  4.     ll u,v,g(gcdE(m%a,a,u,v));
  5.     return x=v-(m/a)*u,y=u,g;
  6. }
  7. ll inv(ll a,ll m=MOD){
  8.     ll x,y,g(gcdE(a,m,x,y));
  9.     return g==1?(x%m+m)%m:-1;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment