LOJ #562. 「LibreOJ Round #9」Tangjz 的背包

题解：

$P=998244353,r=19190506,q=\frac{1}{r}$$P = 998244353, r = 19190506, q = \frac{1}{r}$ ，那么答案就是 ${r}^{p-m}\left[{x}^{m}\right]\prod _{i=0}^{n-1}\left(1+{q}^{i}x\right)$$r^{p-m} [x^m]\prod_{i=0}^{n-1} (1 + q^ix)$

$a$$a$$q$$q$$P$$P$ 的阶， $F\left(n\right)=\prod _{i=1}^{n}\left({q}^{i}-1\right)$$F(n) = \prod_{i=1}^n (q^i-1)$ ，将 $F\left(n\right)$$F(n)$ 分成两部分，模 $P$$P$$0$$0$ 的和不为 $0$$0$ 分别计算，有：

$F\left(n\right)=\left(\prod _{i=1}^{⌊\frac{n}{a}⌋}\left({q}^{ai}-1\right)\right)\left(\prod _{i=1,a\nmid i}^{n}\left({q}^{i}-1\right)\right)$$F(n) = (\prod_{i=1}^{\lfloor \frac{n}{a} \rfloor} (q^{ai} - 1)) (\prod_{i=1, a\nmid i}^n (q^i - 1))$

${q}^{ai}-1=\left({q}^{a}-1\right)\left(\sum _{j=0}^{i-1}{q}^{aj}\right)$$q^{ai} - 1 = (q^a - 1) (\sum_{j=0}^{i-1} q^{aj})$

代码：

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1100000;
const int q = 768906335;
const int r = 19190506;
const int mod = 998244353;
const int period = 917504;

int f[N], g[N], fac[N], ifac[N];

int add(int x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
return x;
}

int mul(int x, int y) {
return (ll)x * y % mod;
}

int power(int x, int y) {
int result = 1;
while (y) {
if (y & 1) {
result = mul(result, x);
}
x = mul(x, x);
y >>= 1;
}
return result;
}

int binom(int n, int m) {
return mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int fact(int n, int m) {
return mul(f[n], mul(g[m], g[n - m]));
}

int main() {
#ifdef wxh010910
freopen("input.txt", "r", stdin);
#endif
f[0] = g[0] = 1;
for (int i = 1, coef = 1; i < period; ++i) {
coef = mul(coef, q);
f[i] = mul(f[i - 1], coef - 1);
g[i] = mul(g[i - 1], power(coef - 1, mod - 2));
}
fac[0] = ifac[0] = fac[1] = ifac[1] = 1;
int limit = (1000000000000ll + period - 1) / period;
for (int i = 2; i <= limit; ++i) {
fac[i] = mul(fac[i - 1], i);
ifac[i] = mul(mod - mod / i, ifac[mod % i]);
}
for (int i = 2; i <= limit; ++i) {
ifac[i] = mul(ifac[i - 1], ifac[i]);
}
int T;
scanf("%d", &T);
while (T--) {
ll n, m;
scanf("%lld %lld", &n, &m);
if (n / period != m / period + (n - m) / period) {
puts("0");
continue;
}
int p = ((n - m) % period) * (m % period) % period;
}
return 0;
}

07-02 228

12-27 290

06-03 28

06-27 56

07-05 530

10-24 227

04-23 199

05-25 2054

06-21 17

10-31 171

下载赞rp

©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。