fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3. int t;
  4. int a , n , p;
  5. int ans;
  6. int power(int a , int b , int mod){
  7. int res = 1;
  8. while(b){
  9. if(b & 1){
  10. res = (1LL * res * a) % mod;
  11. }
  12. a = (1LL * a * a) % mod;
  13. b >>= 1;
  14. }
  15. return res;
  16. }
  17. int main(){
  18. scanf("%d" , &t);
  19. for(int tc = 1 ; tc <= t ; ++tc){
  20. scanf("%d %d %d" , &a , &n , &p);
  21. ans = a;
  22. for(int i = 1 ; i <= n ; ++i){
  23. ans = power(ans , i , p);
  24. }
  25. printf("Case #%d: %d\n" , tc , ans);
  26. }
  27. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty