fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int liczbaJednosci(int, int);
  6. int nLiczba2;
  7.  
  8. int main()
  9. {
  10. int nTestow, nLiczba1, nModulo2;
  11.  
  12. cin >> nTestow;
  13. if(nTestow<0 || nTestow>10)
  14. return 0;
  15. for (int i=0; i<nTestow; i++)
  16. {
  17. cin >> nLiczba1 >> nLiczba2;
  18. nModulo2 = nLiczba2%4;
  19. if(((nLiczba1 || nLiczba2)<0) || ((nLiczba1 || nLiczba2)>1000000000))
  20. return 0;
  21.  
  22. cout << liczbaJednosci(nLiczba1%10, nModulo2) << endl;
  23.  
  24. }
  25. return 0;
  26. }
  27.  
  28. int liczbaJednosci(int a, int b)
  29. {
  30. if(a==0 && nLiczba2!=0)
  31. return 0;
  32. else if(a==1 || nLiczba2==0)
  33. return 1;
  34. else if((a==2 && b==1) || (a==8 && b==3))
  35. return 2;
  36. else if((a==3 && b==1) || (a==7 && b==3))
  37. return 3;
  38. else if((a==2 && b==2) || (a==4 && (b==1 || b==3)) || (a==8 && b==2))
  39. return 4;
  40. else if(a==5)
  41. return 5;
  42. else if((a==2 && b==0) || (a==4 && (b==2 || b==0)) || a==6 || (a==8 && b==0))
  43. return 6;
  44. else if((a==3 && b==3) || (a==7 && b==1))
  45. return 7;
  46. else if((a==2 && b==3) || (a==8 && b==1))
  47. return 8;
  48. else if((a==3 && b==2) || (a==7 && b==2) || (a==9 && (b==1 || b==3)))
  49. return 9;
  50. }
  51.  
Success #stdin #stdout 0s 4316KB
stdin
2
2 3
3 3
stdout
8
7