Solution
wans====GP−1k∑i=0n(ni)[k∣i]∑i=0n(ni)1k∑j=0k−1wij1k∑j=0k−1(wj+1)n
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> Pairs;
const int G = 3;
const int MOD = 998244353;
inline int pow(int a, int b) {
int c = 1;
while (b) {
if (b & 1) c = (ll)c * a % MOD;
b >>= 1; a = (ll)a * a % MOD;
}
return c;
}
inline int inv(int x) {
return pow(x, MOD - 2);
}
inline void add(int &x, int a) {
x += a; while (x >= MOD) x -= MOD;
}
ll nn;
int n, k, w, w0, ans;
int main(void) {
cin >> nn >> k; n = nn % (MOD - 1);
w0 = w = pow(G, (MOD - 1) / k);
for (int j = 0; j < k; j++) {
add(ans, pow(w0 + 1, n));
w0 = (ll)w0 * w % MOD;
}
ans = (ll)ans * inv(k) % MOD;
cout << ans << endl;
return 0;
}