Advertisement
Saleh127

Live ar 4104

Aug 16th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. ll mod(ll a,ll c,ll m)
  5. {
  6.  
  7. if(c==0) return 1;
  8. ll x=mod(a,c/2,m);
  9. x=(x*x)%m;
  10. if(c%2==1)
  11. {
  12. x=(x*a)%m;
  13. }
  14. return x;
  15. }
  16. int main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);cout.tie(0);
  20.  
  21. ll n,a,c,d,e,f,i,j,k,l;
  22. while(cin>>n && n)
  23. {
  24.  
  25. while(n--)
  26. {
  27. cin>>a>>c>>d;
  28. cout<<mod(a,c,d)<<endl;
  29. }
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement