fork download
  1. //---------Think twice code once----------/
  2. #include<bits/stdc++.h>
  3. typedef long long ll;
  4. using namespace std;
  5. ll power(ll a,ll b,ll m)
  6. {
  7. ll mul=1;
  8. a=(a%m);
  9. while(b>0)
  10. {
  11. if(b&1)
  12. {
  13. mul=((mul%m*a%m)%m);
  14. }
  15. b=b>>1;
  16. a=((a*a)%m);
  17. }
  18. return mul;
  19. }
  20. int main()
  21. {
  22. int t;
  23. cin>>t;
  24. while(t--)
  25. {
  26. ll a,b,n,ans;
  27. cin>>a>>b>>n;
  28. ans=power(a,b,n);
  29. cout<<ans%n<<endl;
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 15232KB
stdin
2
10 6 9
9 5 3
stdout
1
0