|
- #include<iostream>
- using namespace std;
- long long int b,aa,p,k;
- int i,j;
- long long int ksm(long long int a,long long int c,long long int d)
- {
- int t=1;aa=a;
- while(c>0)
- {
- if(c%2!=0)t=t*aa%k;
- aa=aa*aa%k;c=c/2;
- }
- return t%k;
- }
- int main()
- {
- cin>>b>>p>>k;
- cout<<b<<"^"<<p<<" mod "<<k<<"="<<ksm(b,p,k);
- return 0;
- }
复制代码 |
|