传送门
\(d=1\) 输出 \(k^n\)
\(d=2\),构造生成函数,就是求
\[(\sum_{i=0}^{\infty}[2|i]\frac{x^i}{i!})^k[x^n]=(\frac{e^x+e^{-x}}{2})^k\]
直接二项式定理展开求 \(n\) 次项系数即可
\(d=3\),构造生成函数,就是求
\[(\sum_{i=0}^{\infty}[3|i]\frac{x^i}{i!})^k[x^n]\]
\(19491001-1\) 正好是 \(3\) 的倍数,直接单位根弄一下,里面的东西
\[\frac{1}{3}\sum_{i=0}^{\infty}\frac{x^i}{i!}\sum_{j=0}^{2}w_3^{ij}\]
\[=\frac{1}{3}\sum_{j=0}^{2}\sum_{i=0}^{\infty}\frac{(xw_3^j)^i}{i!}=\frac{1}{3}(e^x+e^{xw_3^1}+e^{xw_3^2})\]
\(k\le 1000\),就直接 \(k^2\) 枚举然后计算就好了
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn(5e5 + 5);
const int mod(19491001);
int n, k, d, fac[maxn], inv[maxn];
inline void Inc(int &x, int y) {
x = x + y >= mod ? x + y - mod : x + y;
}
inline int Pow(ll x, ll y) {
register ll ret = 1;
for (x %= mod, y %= mod - 1; y; y >>= 1, x = x * x % mod)
if (y & 1) ret = ret * x % mod;
return ret;
}
inline int C(int x, int y) {
if (y > x || x < 0 || y < 0) return 0;
return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
register int i, j, ans, w1, w2, e;
scanf("%d%d%d", &n, &k, &d);
if (d == 1) printf("%d\n", Pow(k, n));
else if (d == 2) {
fac[0] = fac[1] = inv[0] = inv[1] = 1;
for (i = 2; i < maxn; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
for (i = 2; i < maxn; ++i) fac[i] = (ll)fac[i - 1] * i % mod, inv[i] = (ll)inv[i] * inv[i - 1] % mod;
for (i = ans = 0; i <= k; ++i) Inc(ans, (ll)Pow((i * 2 - k + mod) % mod, n) * C(k, i) % mod);
ans = (ll)ans * Pow(2, (ll)k * (mod - 2) % (mod - 1)) % mod;
printf("%d\n", ans);
}
else {
fac[0] = fac[1] = inv[0] = inv[1] = 1;
for (i = 2; i < maxn; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
for (i = 2; i < maxn; ++i) fac[i] = (ll)fac[i - 1] * i % mod, inv[i] = (ll)inv[i] * inv[i - 1] % mod;
w1 = Pow(7, (mod - 1) / 3), w2 = (ll)w1 * w1 % mod;
for (ans = i = 0; i <= k; ++i)
for (j = k - i; ~j; --j) {
e = (i + (ll)j * w1 + (k - i - j) * w2) % mod;
Inc(ans, (ll)C(k, i) * C(k - i, j) % mod * Pow(e, n) % mod);
}
ans = (ll)ans * Pow(3, (ll)k * (mod - 2) % (mod - 1)) % mod;
printf("%d\n", ans);
}
return 0;
}