Submit Info #5796

Problem Lang User Status Time Memory
$\sum_{i=0}^{\infty} r^i i^d$ cpp chocorusk AC 671 ms 344.67 MiB

ケース詳細
Name Status Time Memory
0_00 AC 1 ms 0.72 MiB
0_01 AC 1 ms 0.67 MiB
0_02 AC 667 ms 344.66 MiB
2_00 AC 2 ms 0.66 MiB
2_01 AC 0 ms 0.68 MiB
2_02 AC 3 ms 1.05 MiB
2_03 AC 27 ms 17.88 MiB
2_04 AC 671 ms 344.67 MiB
2_05 AC 660 ms 344.67 MiB
example_00 AC 2 ms 0.68 MiB

#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; const ll MOD=998244353; ll powmod(ll a, ll k){ ll ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=MOD; } ap=ap*ap; ap%=MOD; k>>=1; } return ans; } ll inv(ll a){ return powmod(a, MOD-2); } ll f[10000010], invf[10000010]; void fac(int n){ f[0]=1; for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD; invf[n]=inv(f[n]); for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD; } ll comb(int x, int y){ if(!(0<=y && y<=x)) return 0; return f[x]*invf[y]%MOD*invf[x-y]%MOD; } int p[10000010]; ll b[10000010], c[10000010]; int main() { ll r; int d; cin>>r>>d; if(d==0){ cout<<inv((1-r+MOD)%MOD)<<endl; return 0; } fac(d+1); for(int i=2; i<=d; i++){ if(p[i]) continue; for(int j=i; j<=d; j+=i){ p[j]=i; } } b[1]=1; for(int i=2; i<=d; i++){ if(p[i]==i) b[i]=powmod(i, d); else b[i]=b[p[i]]*b[i/p[i]]%MOD; } ll ap=1; for(int i=0; i<=d; i++){ (b[i]*=ap)%=MOD; c[i]=comb(d+1, i)*ap%MOD; if(i&1) c[i]=MOD-c[i]; (ap*=r)%=MOD; } ll s=0, ans=0; for(int i=0; i<=d; i++){ s+=c[i]; if(s>=MOD) s-=MOD; (ans+=s*b[d-i])%=MOD; } (ans*=powmod((1-r+MOD)%MOD, MOD-d-2))%=MOD; cout<<ans<<endl; return 0; }