// ubsan: undefined // accoders #include<bits/stdc++.h> usingnamespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #else #define debug(...) void(0) #endif #define int long long inlineintread(){ int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } #define Z(x) (x) * (x) #define pb push_back #define fi first #define se second //#define M #define mo 998244353 //#define N #define B 623 inlinevoidMod(int &a){ if (a >= mo || a <= -mo) a %= mo; if (a < 0) a += mo; } inlinevoidAdd(int &a, int b){ a += b; Mod(a); } int n, m, i, j, k, T, W; int f[B * 3 + 10][3 * B + 10]; int g[2][300010]; int ans, M;
namespace Sol2 { int ans = 0, s; voidMain(){ for (i = 1; i <= n; ++i) { s = (1 + i) * i / 2; if (s > n) continue; if ((n - s) % i == 0) Add(ans, 1); } printf("%lld\n", ans); } } // namespace Sol2
signedmain(){ freopen("dazzling.in", "r", stdin); freopen("dazzling.out", "w", stdout); #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // srand(time(NULL)); // T=read(); // while(T--) { // // } n = read(); W = read(); M = 3 * B; if (W == 0) return Sol2 ::Main(), 0; for (i = 1; i <= n; ++i) { for (j = 1; j <= 3 * B && j <= i; ++j) { if (i == j && i <= B) f[i % M][j]++; Add(f[(i + j + 1) % M][j + 1], f[i % M][j]); if (j > 1) Add(f[(i + j - 1) % M][j - 1], f[i % M][j] * W % mo); } if (i == n) { for (j = 1; j <= 3 * B && j <= i; ++j) Add(ans, f[n % M][j]); } for (j = 1; j <= 3 * B && j <= i; ++j) f[i % M][j] = 0; } for (i = 3 * B; i >= 0; --i) { for (j = B + 1; j * (i + 1) <= 3 * n; ++j) g[i & 1][j * (i + 1)]++; if (!i) break; // debug("%lld : 1246[%lld] 1248[%lld]\n", i, g[i & 1][1246], g[i & 1][1248]); for (j = 1; j <= 3 * n; ++j) { if (j + i <= 3 * n) Add(g[(i - 1) & 1][j + i], g[i & 1][j] % mo); if (j - i >= 1) Add(g[(i - 1) & 1][j - i], g[i & 1][j] * W % mo); g[i & 1][j] = 0; } } debug(">> %lld\n", g[0][n]); Add(ans, g[0][n]); printf("%lld\n", ans); return0; }