fork download
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5. int ile;
  6. unsigned long long int a,b;
  7.  
  8. int main()
  9. {
  10. cin>>ile;
  11. for ( int i=0; i<ile; i++)
  12. {
  13. cin>>a>>b;a=a%10;
  14. if(b==0) cout<<1<<endl;
  15. else
  16. {
  17. switch (a)
  18. {
  19. case 0: cout<<0<<endl; break;
  20. case 1: cout<<1<<endl; break;
  21. case 2:
  22. {
  23. switch (b%4)
  24. {
  25. case 1:cout<<2<<endl; break;
  26. case 2:cout<<4<<endl; break;
  27. case 3:cout<<8<<endl; break;
  28. case 0: cout<<6<<endl; break;
  29. }
  30. } break;
  31.  
  32. case 3:
  33. {
  34. switch (b%4)
  35. {
  36. case 1: cout<<3<<endl; break;
  37. case 2: cout<<9<<endl; break;
  38. case 3: cout<<7<<endl; break;
  39. case 0: cout<<1<<endl; break;
  40. }
  41. } break;
  42. case 4:
  43. switch (b%2)
  44. {
  45. case 1: cout<<4<<endl; break;
  46. case 0: cout<<6<<endl; break;
  47. } break;
  48. case 5: cout<<5<<endl; break;
  49. case 6: cout<<6<<endl; break;
  50. case 7:
  51. {
  52. switch (b%4)
  53. {
  54. case 1: cout<<7<<endl; break;
  55. case 2: cout<<9<<endl; break;
  56. case 3: cout<<3<<endl; break;
  57. case 0: cout<<1<<endl; break;
  58. }
  59. } break;
  60. case 8:
  61. {
  62. switch (b%4)
  63. {
  64. case 1: cout<<8<<endl; break;
  65. case 2: cout<<4<<endl; break;
  66. case 3: cout<<2<<endl; break;
  67. case 0: cout<<6<<endl; break;
  68. }
  69. } break;
  70. case 9:
  71. {
  72. switch (b%2)
  73. {
  74. case 1: cout<<1<<endl; break;
  75. case 0: cout<<9<<endl; break;
  76. }
  77. } break;
  78.  
  79. }}
  80.  
  81. }
  82. return 0;
  83. }
  84.  
  85.  
  86.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty