#include <iostream>
using namespace std;
int f(int n, int k);
int g(int n, int k);
int f(int n, int k) {
if (n == 1)
return k;
return (k - 1) * (f(n - 1, k) + g(n - 1, k));
}
int g(int n, int k) {
return 1;
return f(n - 1, k);
signed main() {
int n, k;
cin >> n >> k;
cout << f(n, k);
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int f(int n, int k);
int g(int n, int k);
int f(int n, int k) {
if (n == 1)
return k;
return (k - 1) * (f(n - 1, k) + g(n - 1, k));
}
int g(int n, int k) {
if (n == 1)
return 1;
return f(n - 1, k);
}
signed main() {
int n, k;
cin >> n >> k;
cout << f(n, k);
return 0;
}