Advertisement
hkshakib

Untitled

Jul 28th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. long long binpow(long long a, long long b, long long m)
  4. {
  5. a %= m;
  6. long long res = 1;
  7. while (b > 0)
  8. {
  9. if (b & 1)
  10. res = res * a % m;
  11. a = a * a % m;
  12. b >>= 1;
  13. }
  14. return res;
  15. }
  16. int main()
  17. {
  18. int t;
  19. cin>>t;
  20. while(t--)
  21. {
  22. long long a,b,c;
  23. cin>>a>>b>>c;
  24.  
  25. cout<<binpow(a,b,c)<<endl;
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement