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