fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,a,b,res,x,y;
  6. cin >> t;
  7. int look[][4] = {{0,0,0,0},
  8. {1,1,1,1},
  9. {2,4,8,6},
  10. {3,9,7,1},
  11. {4,6,4,6},
  12. {5,5,5,5},
  13. {6,6,6,6},
  14. {7,9,3,1},
  15. {8,4,2,6},
  16. {9,1,9,1}};
  17. while (t--)
  18. {
  19. cin >> a >> b;
  20. x = a%10;
  21. y = b%4;
  22. if ( b == 0)
  23. res = 1;
  24. else if ( y == 0)
  25. res = look[x][3];
  26. else
  27. res = look[x][y-1];
  28. cout << res << endl;
  29. }
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 16064KB
stdin
3
2 5
3 9
5 0
stdout
2
3
1