Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <map>
- #include <math.h>
- using namespace std;
- int main() {
- int n, k;
- cin >> n >> k;
- if (n >= 5) {
- switch (k) {
- case 1:
- cout << 4;
- break;
- case 2:
- cout << 8;
- break;
- case 3:
- cout << 5;
- break;
- }
- } else {
- int a[5], b[5];
- a[0] = 1;
- b[0] = 1;
- for (int i = 1; i <= n; i++) {
- a[i] = a[i - 1] * i;
- b[i] = b[i - 1] * i;
- }
- for (int i = 2; i <= k; i++) {
- for (int j = 0; j <= n; j++) {
- a[j] *= (j == 0 ? 1 : b[j]);
- }
- }
- int sum = 0;
- for (int i = 0; i <= n; i++) {
- sum += a[i];
- }
- while (sum != 0) {
- if (sum % 10 != 0) {
- cout << sum % 10;
- break;
- }
- sum /= 10;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement