Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int modularExpo(int a, int b, int c){
- a = a % c;
- int res = 1;
- while(b > 0){
- if(b&1){
- res = (res * a ) % c;
- }
- a = a * a % c;
- // b >>= 1;
- b = b/2;
- }
- return res;
- }
- int main(){
- int a, b, c;
- cin>>a>>b>>c;
- cout<<modularExpo(a, b, c)<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment