несложная динамика)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
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++)
d[i] = (d[i-1]+d0[i-1])*(k-1);
d0[i] = d[i-1];
}
cout << d[n] + d0[n];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin >> n >> k;
solve(n,k);
несложная динамика)
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
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++)
{
d[i] = (d[i-1]+d0[i-1])*(k-1);
d0[i] = d[i-1];
}
cout << d[n] + d0[n];
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin >> n >> k;
solve(n,k);
}