Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FI(_n) for(int i = 0;i<(_n);i++)
- #define FJ(_n) for(int j = 0;j<(_n);j++)
- #define pb push_back
- #define all(c) c.begin(),c.end()
- using namespace std;
- typedef long long ll;
- const ll INF = 1e18 + 1;
- #define ndbg 1
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifdef ndbg
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #endif
- cin.tie(0);cout.tie(0);
- ll n, k;
- cin >> n >> k;
- if(k == 0)
- {
- cout << ((n + 1) % 10 == 0 ? ( (n + 1) % 100 / 10 == 0 ? (n + 1) % 1000 / 100 : (n + 1) % 100 / 10) : (n + 1) % 10 );
- return 0;
- }
- ll fact[] = {1, 1, 2, 6, 24};
- ll sum = 0;
- for(int i = 0; i <= min(1ll*4, n); i++)
- {
- ll ch = 1;
- for(int j = 0; j < k; j++) ch *= fact[i];
- sum += ch;
- }
- while(sum % 10 == 0) sum /= 10;
- cout << sum % 10;
- #ifdef ndbg
- cin.close();
- cout.close();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement