求:
$$
\sum_{i=0}^{n}\sum_{j=0}^{i}S_{i}^{j}2^jj!
$$其中:$1 \le n \le 10^5$,同时 $S_{i}^{j}$ 表示第二类斯特林数
$$
\begin{aligned}
&\sum_{i=0}^{n}\sum_{j=0}^{i}S_{i}^{j}2^jj! \\
=&\sum_{i=0}^{n}\sum_{j=0}^{n}S_{i}^{j}2^jj! \\
=&\sum_{i=0}^{n}\sum_{j=0}^{i}2^jj!\sum_{k=0}^{j}\frac{(-1)^{k}}{k!}\frac{(j-k)^i}{(j-k)!} \\
=&\sum_{j=0}^{n}2^jj!\sum_{k=0}^{j}\frac{(-1)^k}{k!}\frac{\sum_{i=0}^{n}(j-k)^i}{(j-k)!} \\
=&\sum_{j=0}^{n}2^jj!\sum_{k=0}^{j}f(k)g(j-k) \\
=&\sum_{j=0}^{n}2^jj!(f \times g)(j)
\end{aligned}
$$
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 5e5 + 10, mod = 998244353; 5 ll pw(ll a, ll b) { 6 ll r = 1; 7 for(a %= mod ; b ; b >>= 1, a = a * a % mod) 8 if(b & 1) 9 r = r * a % mod; 10 return r; 11 } 12 const ll G[2] = { 3, pw(3, mod - 2) }; 13 14 int n; 15 ll fac[N], invfac[N], a[N], f[N], g[N], h[N]; 16 17 int rev(int x, int n) { 18 int res = 0; 19 for(int i = 0 ; (1 << i) < n ; ++ i) 20 res = (res << 1) | ((x >> i) & 1); 21 return res; 22 } 23 24 void ntt(ll *src, int len, int ty) { 25 for(int i = 0 ; i < len ; ++ i) a[rev(i, len)] = src[i]; 26 27 for(int i = 2 ; i <= len ; i <<= 1) { 28 ll wn = pw(G[ty], (mod - 1) / i); 29 for(int j = 0 ; j < len ; j += i) { 30 ll w = 1; 31 for(int k = j ; k < j + i / 2 ; ++ k) { 32 ll u = a[k], v = w * a[k + i / 2]; 33 a[k] = (u + v) % mod; 34 a[k + i / 2] = (u - v) % mod; 35 w = w * wn % mod; 36 } 37 } 38 } 39 40 ll inv = pw(len, mod - 2); 41 for(int i = 0 ; i < len ; ++ i) { 42 src[i] = a[i]; 43 if(ty) { 44 src[i] = src[i] * inv % mod; 45 } 46 } 47 } 48 49 int main() { 50 scanf("%d", &n); 51 ll ans = 0; 52 53 int len = 1; while(len <= 2 * (n + 1) + 10) len <<= 1; 54 55 fac[0] = invfac[0] = 1; 56 for(int i = 1 ; i <= len ; ++ i) fac[i] = fac[i - 1] * i % mod; 57 invfac[len] = pw(fac[len], mod - 2); 58 for(int i = len - 1 ; i >= 1 ; -- i) invfac[i] = invfac[i + 1] * (i + 1) % mod; 59 60 for(int i = 0 ; i <= n ; ++ i) { 61 f[i] = (i & 1 ? -1 : 1) * invfac[i] % mod; 62 g[i] = i == 0 ? 1 : i == 1 ? n + 1 : (pw(i, n + 1) - 1) % mod * pw(fac[i] * (i - 1) % mod, mod - 2) % mod; 63 } 64 65 ntt(f, len, 0), ntt(g, len, 0); 66 for(int i = 0 ; i < len ; ++ i) f[i] = f[i] * g[i] % mod; 67 ntt(f, len, 1); 68 69 for(int i = 0 ; i <= n ; ++ i) 70 ans = (ans + pw(2, i) * fac[i] % mod * f[i] % mod) % mod; 71 printf("%lld\n", (ans % mod + mod) % mod); 72 }