Guest User

Untitled

a guest
Dec 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. using namespace std;
  4. int modularExpo(int a, int b, int c){
  5.     a = a % c;
  6.     int res = 1;
  7.     while(b > 0){
  8.         if(b&1){
  9.             res = (res * a ) % c;
  10.         }
  11.         a = a * a % c;
  12.         // b >>= 1;
  13.         b = b/2;
  14.     }
  15.     return res;
  16. }
  17.  
  18. int main(){
  19.     int a, b, c;
  20.     cin>>a>>b>>c;
  21.     cout<<modularExpo(a, b, c)<<endl;
  22.     return 0;
  23. }
Add Comment
Please, Sign In to add comment