Last active
April 29, 2022 00:59
-
-
Save jacky860226/b5258a09e06c5581cb87b2c02f628b93 to your computer and use it in GitHub Desktop.
Long Long Mod Mul
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
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