fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long solve(long long a,long long b, long long m)
  4. {
  5. if (b==0) return 1%m;
  6. else if (b%2==0)
  7. {
  8. long long x = solve(a,b/2,m);
  9. return (x*x)%m;
  10. }
  11. else
  12. {
  13. return ((a%m)*(solve(a,b-1,m)%m))%m;
  14. }
  15. }
  16. int main ()
  17. {
  18. long long a,b,m;
  19. while(cin>>a>>b>>m)
  20. {
  21. cout<<solve(a,b,m)<<endl;
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty