Submit Info #5252

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

ケース詳細
Name Status Time Memory
0_00 AC 106 ms 77.80 MiB
0_01 AC 107 ms 77.80 MiB
0_02 AC 2321 ms 77.80 MiB
2_00 AC 108 ms 77.80 MiB
2_01 AC 108 ms 77.87 MiB
2_02 AC 112 ms 77.80 MiB
2_03 AC 200 ms 77.80 MiB
2_04 AC 2355 ms 77.80 MiB
2_05 AC 2329 ms 77.86 MiB
example_00 AC 107 ms 77.88 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 rrep(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; void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;} 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; } //template 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;} }; template<unsigned mod=998244353>struct factorial { using Mint=mint<mod>; vector<Mint> Fact, Finv; public: factorial(int maxx){ Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1); Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i; } Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];} Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];} Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];} }; using Mint=mint<>; factorial<> fact(10100000); int main(){ int r,d; scanf("%d%d",&r,&d); Mint res,add; rep(i,0,d+1){ add+=Mint(r).pow(i)*Mint(i).pow(d); res+=fact.nCr(d+1,i+1)*Mint(-r).pow(d-i)*add; } res/=Mint(1-r).pow(d+1); printf("%d\n",res.val); return 0; }