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 >= 10) {
- switch (k) {
- case 1:
- cout << 4;
- break;
- case 2:
- cout << 8;
- break;
- case 3:
- cout << 5;
- break;
- }
- } else {
- ll arr[10];
- for (int i = 0; i <= n; i++) {
- if (i == 0) {
- arr[i] = 1;
- } else {
- arr[i] = arr[i - 1] * i;
- }
- }
- for (int i = 0; i < k; i++) {
- ll sum = 0;
- for (int j = 0; j <= n; j++) {
- sum += arr[j];
- }
- if (i == k - 1) {
- while (sum != 0) {
- if (sum % 10 != 0) {
- cout << sum % 10;
- break;
- }
- sum /= 10;
- }
- }
- for (int j = 0; j <= n; j++) {
- arr[j] *= arr[j];
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement