多项式求逆的问题
  • 板块学术版
  • 楼主chenyilei
  • 当前回复3
  • 已保存回复3
  • 发布时间2020/6/22 19:47
  • 上次更新2023/11/7 00:12:55
查看原帖
多项式求逆的问题
21001
chenyilei楼主2020/6/22 19:47

void Inv(int n, int *a, int *b) {
	if (n == 1) { b[0] = fpow(a[0], mod - 2); return; }
	Inv(n + 1 >> 1, a, b);
	int x = 1, w = 0;
	while (x < n << 1) x <<= 1, ++w; //为什么这里要到n<<1啊?
	for (int i = 0; i < x; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << w - 1;
	for (int i = 0; i < n; ++i) c[i] = a[i];
	for (int i = n; i < x; ++i) c[i] = 0; //还有这里为什么要赋值成0?
	ntt(x, b, 1);
	ntt(x, c, 1);
	for (int i = 0; i < x; ++i) b[i] = (2ll - 1ll * b[i] * c[i] % mod) * b[i] % mod;
	ntt(x, b, -1);
	for (int i = 0, inv = fpow(x, mod - 2); i < n; ++i) b[i] = 1ll * b[i] * inv % mod;
	for (int i = n; i < x; ++i) b[i] = 0;
}

求教(瑟瑟发抖)

2020/6/22 19:47
加载中...