# Luogu P5349 幂

$r\cdot f_i=\sum_{n=1}^\infty (n-1)^kr^n$

$(1-r)f_i=\sum_{n=1}^\infty (n^k-(n-1)^k)r^n=r\cdot \sum_{n=0}^\infty ((n+1)^k-n^k)r^n$

CODE

#include<cstdio>
#include<cctype>
#include<algorithm>
#define RI register int
#define CI const int&
#define Tp template <typename T>
using namespace std;
const int N=100005,mod=998244353;
int n,r,F[N<<3],G[N<<3],fact[N],inv[N],A[N],invr,mtir,ans;
class FileInputOutput
{
private:
static const int S=1<<21;
char Fin[S],*A,*B;
public:
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
}
#undef tc
}File;
inline int sum(CI x,CI y)
{
int t=x+y; return t>=mod?t-mod:t;
}
inline int sub(CI x,CI y)
{
int t=x-y; return t<0?t+mod:t;
}
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline void init(CI n)
{
RI i; for (fact[0]=i=1;i<=n;++i) fact[i]=1LL*fact[i-1]*i%mod;
for (inv[n]=quick_pow(fact[n]),i=n-1;~i;--i) inv[i]=1LL*inv[i+1]*(i+1)%mod;
}
class Poly_Solver
{
private:
int rev[N<<3],T[N<<3],lim,p;
inline void init(CI n)
{
for (lim=1,p=0;lim<=(n<<1);lim<<=1,++p);
for (RI i=0;i<lim;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<p-1);
}
inline void swap(int& x,int& y)
{
int t=x; x=y; y=t;
}
inline void NTT(int *f,CI opt)
{
RI i; for (i=0;i<lim;++i) if (i<rev[i]) swap(f[i],f[rev[i]]);
for (i=1;i<lim;i<<=1)
{
int m=i<<1,D=quick_pow(3,~opt?(mod-1)/m:mod-1-(mod-1)/m);
for (RI j=0;j<lim;j+=m)
{
int W=1; for (RI k=0;k<i;++k,W=1LL*W*D%mod)
{
int x=f[j+k],y=1LL*f[i+j+k]*W%mod;
f[j+k]=sum(x,y); f[i+j+k]=sub(x,y);
}
}
}
if (!~opt)
{
int Inv=quick_pow(lim); for (i=0;i<lim;++i) f[i]=1LL*f[i]*Inv%mod;
}
}
inline void inv(int *F,int *G,CI n)
{
if (n==1) return (void)(G[0]=quick_pow(F[0]));
inv(F,G,n+1>>1); init(n<<1); copy(F,F+n,T);
NTT(T,1); NTT(G,1); for (RI i=0;i<lim;++i)
G[i]=1LL*sub(2,1LL*T[i]*G[i]%mod)*G[i]%mod;
NTT(G,-1); fill(T+n,T+lim,0); fill(G+n,G+lim,0);
}
public:
inline void get_inv(int *F,int *G,CI n)
{
for (lim=1;lim<=(n<<1);lim<<=1);
fill(T,T+lim,0); fill(G,G+lim,0); inv(F,G,n);
}
}P;
int main()
{
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);