Submit Info #7631

Problem Lang User Status Time Memory
$\sum_{i=0}^{\infty} r^i i^d$ cpp TKO919 AC 699 ms 269.36 MiB

ケース詳細
Name Status Time Memory
0_00 AC 240 ms 116.43 MiB
0_01 AC 244 ms 116.42 MiB
0_02 AC 685 ms 269.36 MiB
2_00 AC 244 ms 116.42 MiB
2_01 AC 238 ms 116.39 MiB
2_02 AC 242 ms 116.55 MiB
2_03 AC 256 ms 124.14 MiB
2_04 AC 694 ms 269.30 MiB
2_05 AC 699 ms 269.33 MiB
example_00 AC 248 ms 116.49 MiB

#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end template<unsigned mod=998244353>struct mint { unsigned val; static unsigned get_mod(){return mod;} unsigned inv() const{ int tmp,a=val,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0)x+=mod; return x; } mint():val(0){} mint(ll x):val(x>=0?x%mod:mod+(x%mod)){} mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;} mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;} mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;} mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;} mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;} mint operator+(const mint& x)const{return mint(*this)+=x;} mint operator-(const mint& x)const{return mint(*this)-=x;} mint operator*(const mint& x)const{return mint(*this)*=x;} mint operator/(const mint& x)const{return mint(*this)/=x;} bool operator==(const mint& x)const{return val==x.val;} bool operator!=(const mint& x)const{return val!=x.val;} }; using Mint=mint<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; unsigned mod=Mint::get_mod(); rep(i,2,maxx){ Fact[i]=Fact[i-1]*i; Inv[i]=Inv[mod%i]*(mod-mod/i); Finv[i]=Finv[i-1]*Inv[i]; } } T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];} T inv(int n){return Inv[n];} T nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];} T nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];} }; factorial<Mint> fact(10100000); vector<Mint> pw_table(int n,ll d){ vector<int> pmin(n); rep(i,2,n)pmin[i]=i; for(int p=2;p<n;p++)if(pmin[p]==p){ for(int q=p*2;q<n;q+=p)chmin(pmin[q],p); } vector<Mint> res(n); if(d==0)res[0]=1; if(n>=2)res[1]=1; rep(i,2,n){ if(pmin[i]==i)res[i]=Mint(i).pow(d); else res[i]=res[pmin[i]]*res[i/pmin[i]]; } return res; } int main(){ int r,d; scanf("%d%d",&r,&d); Mint res,add; vector<Mint> rs(d+1),rev(d+1),pw=pw_table(d+1,d); rs[0]=1; rep(i,0,d)rs[i+1]=rs[i]*r; rev[0]=1; rep(i,0,d)rev[i+1]=rev[i]*(-r); rep(i,0,d+1){ add+=rs[i]*pw[i]; res+=fact.nCr(d+1,i+1)*rev[d-i]*add; } res*=Mint(1-r).pow(Mint::get_mod()-d-2); printf("%d\n",res.val); return 0; }