fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int D;
  5. long long int a,b;
  6. int main()
  7. {
  8. cin >> D;
  9. cout << endl;
  10. for (int i=0; i<D; i++)
  11. {
  12. cin >> a >> b;
  13. int last = a%10;
  14. int lastb =b%10;
  15. if (lastb%4==1)
  16. cout << endl << last<< endl;
  17. else if (lastb%4==2)
  18. cout<< endl << (a*a)%10<< endl;
  19. else if (lastb%4==3)
  20. {
  21. int pot = 1;
  22. for (i=1; i<=lastb; i++)
  23. pot=pot*last;
  24. cout<< endl << pot%10<< endl;
  25. }
  26. else if (lastb%4==0)
  27. {
  28. if (a==5)
  29. cout<< endl << a << endl;
  30. else if (a%2==0)
  31. cout<< endl << 6<< endl;
  32. else
  33. cout<< endl << 1<< endl;
  34. }
  35.  
  36.  
  37. }
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3460KB
stdin
3
2 3
3 3
1000000000 222222222
stdout

8