Skip to content

Instantly share code, notes, and snippets.

@maskmanlucifer
Created June 10, 2021 13:03
Show Gist options
  • Save maskmanlucifer/e896431aaf46c4176ebe2f080cdd12d9 to your computer and use it in GitHub Desktop.
Save maskmanlucifer/e896431aaf46c4176ebe2f080cdd12d9 to your computer and use it in GitHub Desktop.
>> Binary exponentiation
>>> Resources:
T-1: https://cp-algorithms.com/algebra/binary-exp.html
>>> Implementation:
ll be(ll a,ll b)
{
ll ans=1;
a%=M;
while(b)
{
if(b&1)
{
ans=(ans*a)%M;
}
a%=M;
a=(a*a)%M;
b/=2;
}
return ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment