Saleh127

Spoj lastdig

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