Skip to content

Instantly share code, notes, and snippets.

@jacky860226
Last active April 29, 2022 00:59
Show Gist options
  • Save jacky860226/b5258a09e06c5581cb87b2c02f628b93 to your computer and use it in GitHub Desktop.
Save jacky860226/b5258a09e06c5581cb87b2c02f628b93 to your computer and use it in GitHub Desktop.
Long Long Mod Mul
using ull = unsigned long long;
ull _mod_mul(ull a,ull b,ull m){
a%=m,b%=m;
ull ans=0;
for(;b;b>>=1){
if(b&1){
ans+=a;
if(ans>=m)ans-=m;
}
a<<=1;
if(a>=m)a-=m;
}
if(ans>=m)ans-=m;
else if(ans<0)ans+=m;
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment