P5395 【模板】第二类斯特林数·行
题目描述
Solution
这题是[Tjoi2016&Heoi2016]求和的前置技能啊……
我似乎直接跳过这题,去做应用了 。
Code
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>
#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
using namespace std;
template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }
typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;
const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=167772161;
const int G=3;
const int Gi=(mods+1)/G;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
int f=1,x=0; char c=getchar();
while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
return x*f;
}
int f[MAXN],g[MAXN],rev[MAXN],Limit,L;
int quick_pow(int x,int y)
{
int ret=1;
for (;y;y>>=1)
{
if (y&1) ret=1ll*ret*x%mods;
x=1ll*x*x%mods;
}
return ret;
}
int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
void Number_Theoretic_Transform(int *A,int type)
{
for (int i=0;i<Limit;i++) if (i<rev[i]) swap(A[i],A[rev[i]]);
for (int mid=1;mid<Limit;mid<<=1)
{
int Wn=quick_pow(type==1?G:Gi,(mods-1)/(mid<<1));
for (int j=0;j<Limit;j+=(mid<<1))
for (int k=j,w=1;k<j+mid;w=1ll*w*Wn%mods,k++)
{
int x=A[k],y=1ll*w*A[k+mid]%mods;
A[k]=upd(x,y),A[k+mid]=upd(x,mods-y);
}
}
}
int main()
{
int n=read();
f[0]=1;
for (int i=1;i<=n;i++) f[i]=1ll*f[i-1]*i%mods;
f[n]=quick_pow(f[n],mods-2);
for (int i=n-1;i>=0;i--) f[i]=1ll*f[i+1]*(i+1)%mods;
for (int i=0;i<=n;i++)
{
g[i]=(i&1)?mods-f[i]:f[i];
f[i]=1ll*f[i]*quick_pow(i,n)%mods;
// cout<<i<<":"<<f[i]<<" "<<g[i]<<endl;
}
Limit=1,L=0;
while (Limit<=n<<1) Limit<<=1,L++;
for (int i=1;i<Limit;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(L-1));
Number_Theoretic_Transform(f,1);
Number_Theoretic_Transform(g,1);
for (int i=0;i<=Limit;i++) f[i]=1ll*f[i]*g[i]%mods;
Number_Theoretic_Transform(f,-1);
int invLimit=quick_pow(Limit,mods-2);
for (int i=0;i<=n;i++) printf("%d ",1ll*f[i]*invLimit%mods);
return 0;
}