fork download
  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. #define maxx 1000
  4. using namespace std;
  5. long long powerM(long long b,long long p,long long m)
  6. {
  7. if(p==0)return 1;
  8. long long temp=powerM(b,p/2,m);
  9. temp=(temp%m*temp%m)%m;
  10. if(p%2==0)return temp%m;
  11. else
  12. return ((b%m)*(temp%m))%m;
  13. }
  14. int main() {
  15. long long B,P,M;
  16. while(scanf("%lld %lld %lld",&B,&P,&M)!=EOF)
  17. {
  18. long long ans=powerM(B,P,M)%M;
  19. printf("%lld\n",ans);
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
Standard output is empty