Skip to content

Commit 5090f82

Browse files
committed
sum exp times poly limit
1 parent 8af7cf6 commit 5090f82

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

verify/poly/sum_exp_poly.test.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// @brief $\sum\limits_{i=0}^\infty r^i i^d$
2+
#define PROBLEM "https://judge.yosupo.jp/problem/sum_of_exponential_times_polynomial_limit"
3+
#pragma GCC optimize("Ofast,unroll-loops")
4+
#define CP_ALGO_MAXN 1 << 24
5+
#include "cp-algo/math/poly.hpp"
6+
#include <bits/stdc++.h>
7+
8+
using namespace std;
9+
using namespace cp_algo::math;
10+
11+
const int mod = 998244353;
12+
typedef modint<mod> base;
13+
typedef poly_t<base> polyn;
14+
15+
base nCr(int n, int r) {
16+
return fact<base>(n) * rfact<base>(r) * rfact<base>(n-r);
17+
}
18+
19+
polyn xm1k(size_t k) {
20+
polyn::Vector ans(k+1);
21+
for(int i = 0; i <= k; i++) {
22+
ans[i] = (k - i) & 1 ? -nCr(k, i) : nCr(k, i);
23+
}
24+
return ans;
25+
}
26+
27+
void solve() {
28+
int r, d;
29+
cin >> r >> d;
30+
polyn num = polyn(bpow(base(1-r), d+1)) - bpow(base(r), d+1) * xm1k(d+1);
31+
polyn den = polyn(bpow(base(1-r), d+2)) - bpow(base(1-r), d+1) * r * (polyn::xk(1) - polyn(base(1)));
32+
polyn H = num / den;
33+
base ans = 0;
34+
35+
base id[d+1];
36+
vector<int> lp(d+1);
37+
id[0] = bpow(base(0), d);
38+
id[1] = 1;
39+
for(int i = 2; i <= d; i++) {
40+
if(lp[i] == 0) {
41+
id[i] = bpow(base(i), d);
42+
for(int j = i; j <= d; j += i) {
43+
lp[j] = i;
44+
}
45+
} else {
46+
id[i] = id[lp[i]] * id[i / lp[i]];
47+
}
48+
}
49+
50+
for(int i = 0; i <= d; i++) {
51+
ans += H[i] * id[i];
52+
}
53+
cout << ans << endl;
54+
}
55+
56+
signed main() {
57+
//freopen("input.txt", "r", stdin);
58+
ios::sync_with_stdio(0);
59+
cin.tie(0);
60+
int t;
61+
t = 1;// cin >> t;
62+
while(t--) {
63+
solve();
64+
}
65+
}

0 commit comments

Comments
 (0)