Advertisement
Diene

Untitled

Jan 23rd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int m,pot,resultado;
  7.     long long b,p;
  8.  
  9.     while(cin>>b){
  10.         cin>>p>>m;
  11.         pot=b%m;
  12.         resultado=1;
  13.         for(p;p>0;p/=2){
  14.             if(p%2==1){
  15.                 resultado=(resultado*pot)%m;
  16.                 p--;
  17.             }
  18.                 pot=(pot*pot)%m;
  19.         }
  20.     cout<< resultado <<endl;
  21.     }
  22.  
  23.     return 0;
  24.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement