несложная динамика)
#include
#include
#include
#include
#include
#include
using namespace std;
#define int long long
const int MAXN = 100,MAXK = 100;
int d[MAXN], d0[MAXN];
void solve(int n, int k)
{
d[1] = k-1;
d0[0] = 0;
for(int i = 2; i <= n; i++)</strong>
{
d[i] = (d[i-1]+d0[i-1])*(k-1);
d0[i] = d[i-1];
}
cout << d[n] + d0[n];</strong>
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin >> n >> k;
solve(n,k);
}