Advertisement
kostes

Untitled

Nov 24th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define FI(_n) for(int i = 0;i<(_n);i++)
  3. #define FJ(_n) for(int j = 0;j<(_n);j++)
  4. #define pb push_back
  5. #define all(c) c.begin(),c.end()
  6. using namespace std;
  7. typedef long long ll;
  8. const ll INF = 1e18 + 1;
  9. #define ndbg 1
  10. int main()
  11. {
  12. ios_base::sync_with_stdio(0);
  13. #ifdef ndbg
  14. ifstream cin("input.txt");
  15. ofstream cout("output.txt");
  16. #endif
  17. cin.tie(0);cout.tie(0);
  18.  
  19. ll n, k;
  20. cin >> n >> k;
  21. if(k == 0)
  22. {
  23. cout << ((n + 1) % 10 == 0 ? ( (n + 1) % 100 / 10 == 0 ? (n + 1) % 1000 / 100 : (n + 1) % 100 / 10) : (n + 1) % 10 );
  24. return 0;
  25. }
  26. ll fact[] = {1, 1, 2, 6, 24};
  27. ll sum = 0;
  28. for(int i = 0; i <= min(1ll*4, n); i++)
  29. {
  30. ll ch = 1;
  31. for(int j = 0; j < k; j++) ch *= fact[i];
  32. sum += ch;
  33. }
  34. while(sum % 10 == 0) sum /= 10;
  35. cout << sum % 10;
  36.  
  37.  
  38.  
  39. #ifdef ndbg
  40. cin.close();
  41. cout.close();
  42. #endif
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement