33 lines
487 B
C++
33 lines
487 B
C++
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
|
|
int binExp(int b,int e,int m){
|
|
int r = 1;
|
|
while(e>0){
|
|
if(e%2==1){
|
|
r = (r*b)%m;
|
|
}
|
|
b = b*b %m;
|
|
e = e>>1;
|
|
}
|
|
return r;
|
|
}
|
|
#ifndef ISTEST
|
|
|
|
signed main(){
|
|
cin.sync_with_stdio(false);
|
|
cin.tie(0);
|
|
int a,b,p;
|
|
cin>>a>>b>>p;
|
|
int r= binExp(a,b,p);
|
|
cout<<a<<"^"<<b<<" mod "<<p<<"="<<r<<endl;
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef ISTEST
|
|
int main(){
|
|
assert(binExp(2, 10, 9)==7);
|
|
}
|
|
#endif |