Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created November 28, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HyeonWooKim/4192dbcbb5df2cddad0f3c103fdc684d to your computer and use it in GitHub Desktop.
Save HyeonWooKim/4192dbcbb5df2cddad0f3c103fdc684d to your computer and use it in GitHub Desktop.
BOJ 1629
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
long long b,e,m,o=1;
cin>>b>>e>>m;
b%=m;
while(e)
{
if(e%2==1)
o=(o*b)%m,e--;
else
b=(b*b)%m,e/=2;
}
cout<<o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment