题目大意:给你$n$项多项式$A(x)$,求出$B(x)$满足$B^2(x)\equiv A(x)\pmod{x^n}$

题解:考虑已经求出$B_0(x)$满足$B_0^2(x)\equiv A(x)\pmod{x^{\lceil\frac n 2\rceil}}$
$$
B(x)-B_0(x)\equiv0\pmod{x^{\lceil\frac n 2\rceil}}\\
B^2(x)−2B(x)B_0(x)+B_0^2(x)≡0\pmod{x^n}\\
A(x)-2B(x)B_0(x)+B_0^2(x)≡0\pmod{x^n}\\
B(x)\equiv\dfrac{A(x)+B_0^2(x)}{2B_0(x)}\pmod{x^n}\\
$$


update:(2019-2-10)

$$
B(x)\equiv\dfrac{A(x)+B_0^2(x)}{2B_0(x)}\pmod{x^n}\\
B(x)\equiv\dfrac{A(x)}{2B_0(x)}+\dfrac{B_0(x)}2\pmod{x^n}\\
$$
发现$\dfrac{B_0(x)}2$只会影响$B(x)$数组的前半部分(即$\pmod{x^{\lceil\frac n2\rceil}}$的部分),但是$B(x)\equiv B_0(x)\pmod{x^{\lceil\frac n2\rceil}}$,所以可以不做考虑,直接把$B_0(x)$拉过来

卡点:求$INV$时注意清空数组,防止因为$B$数组不干净导致出锅

C++ Code:

#include <algorithm>
#include <cctype>
#include <cstdio>
#define maxn 262144
const int mod = 998244353, __2 = mod + 1 >> 1; namespace std {
struct istream {
#define M (1 << 21 | 3)
char buf[M], *ch = buf - 1;
inline istream() { fread(buf, 1, M, stdin); }
inline istream& operator >> (int &x) {
while (isspace(*++ch));
for (x = *ch & 15; isdigit(*++ch); ) x = x * 10 + (*ch & 15);
return *this;
}
#undef M
} cin;
struct ostream {
#define M (1 << 21 | 3)
char buf[M], *ch = buf - 1;
inline ostream& operator << (int x) {
if (!x) {*++ch = '0'; return *this;}
static int S[20], *top; top = S;
while (x) {*++top = x % 10 ^ 48; x /= 10;}
for (; top != S; --top) *++ch = *top;
return *this;
}
inline ostream& operator << (const char x) {*++ch = x; return *this;}
inline ~ostream() { fwrite(buf, 1, ch - buf + 1, stdout); }
#undef M
} cout;
} namespace Math {
inline int pw(int base, int p) {
static int res;
for (res = 1; p; p >>= 1, base = static_cast<long long> (base) * base % mod) if (p & 1) res = static_cast<long long> (res) * base % mod;
return res;
}
inline int inv(int x) { return pw(x, mod - 2); }
} inline void reduce(int &x) { x += x >> 31 & mod; }
inline void clear(register int *l, const int *r) {
if (l >= r) return ;
while (l != r) *l++ = 0;
} namespace Poly {
#define N maxn
int lim, s, rev[N];
int Wn[N + 1]; inline void init(const int n) {
lim = 1, s = -1; while (lim < n) lim <<= 1, ++s;
for (register int i = 1; i < lim; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << s;
const int t = Math::pw(3, (mod - 1) / lim);
*Wn = 1; for (register int *i = Wn; i != Wn + lim; ++i) *(i + 1) = static_cast<long long> (*i) * t % mod;
}
inline void FFT(int *A, const int op = 1) {
for (register int i = 1; i < lim; ++i) if (i < rev[i]) std::swap(A[i], A[rev[i]]);
for (register int mid = 1; mid < lim; mid <<= 1) {
const int t = lim / mid >> 1;
for (register int i = 0; i < lim; i += mid << 1)
for (register int j = 0; j < mid; ++j) {
const int X = A[i + j], Y = static_cast<long long> (A[i + j + mid]) * Wn[t * j] % mod;
reduce(A[i + j] += Y - mod), reduce(A[i + j + mid] = X - Y);
}
}
if (!op) {
const int ilim = Math::inv(lim);
for (register int *i = A; i != A + lim; ++i) *i = static_cast<long long> (*i) * ilim % mod;
std::reverse(A + 1, A + lim);
}
} void INV(int *A, int *B, int n) {
if (n == 1) { *B = Math::inv(*A); return ; }
const int len = n + 1 >> 1;
INV(A, B, len); init(len * 3);
static int C[N], D[N];
std::copy(A, A + n, C); clear(C + n, C + lim);
std::copy(B, B + len, D); clear(D + len, D + lim);
FFT(D), FFT(C);
for (register int i = 0; i < lim; ++i) D[i] = (2 - static_cast<long long> (D[i]) * C[i] % mod + mod) * D[i] % mod;
FFT(D, 0); std::copy(D + len, D + n, B + len);
}
void SQRT(int *A, int *B, int n) {
if (n == 1) { *B = 1; return ; }
static int C[N], D[N];
const int len = n + 1 >> 1;
SQRT(A, B, len);
INV(B, D, n), clear(D + n, D + lim);
std::copy(A, A + n, C); clear(C + n, C + lim);
FFT(C), FFT(D);
for (register int i = 0; i < lim; ++i) D[i] = static_cast<long long> (C[i]) * D[i] % mod * __2 % mod;
FFT(D, 0); std::copy(D + len, D + n, B + len);
}
#undef N
} int n, A[maxn], B[maxn];
int main() {
std::cin >> n;
for (int i = 0; i < n; ++i) std::cin >> A[i];
Poly::SQRT(A, B, n);
for (int i = 0; i < n; ++i) std::cout << B[i] << ' ';
std::cout << '\n';
return 0;
}

  

[洛谷P5205]【模板】多项式开根的更多相关文章

  1. 洛谷.3803.[模板]多项式乘法(FFT)

    题目链接:洛谷.LOJ. FFT相关:快速傅里叶变换(FFT)详解.FFT总结.从多项式乘法到快速傅里叶变换. 5.4 又看了一遍,这个也不错. 2019.3.7 叕看了一遍,推荐这个. #inclu ...

  2. 洛谷.3803.[模板]多项式乘法(NTT)

    题目链接:洛谷.LOJ. 为什么和那些差那么多啊.. 在这里记一下原根 Definition 阶 若\(a,p\)互质,且\(p>1\),我们称使\(a^n\equiv 1\ (mod\ p)\ ...

  3. 洛谷.4512.[模板]多项式除法(NTT)

    题目链接 多项式除法 & 取模 很神奇,记录一下. 只是主要部分,更详细的和其它内容看这吧. 给定一个\(n\)次多项式\(A(x)\)和\(m\)次多项式\(D(x)\),求\(deg(Q) ...

  4. 洛谷.4238.[模板]多项式求逆(NTT)

    题目链接 设多项式\(f(x)\)在模\(x^n\)下的逆元为\(g(x)\) \[f(x)g(x)\equiv 1\ (mod\ x^n)\] \[f(x)g(x)-1\equiv 0\ (mod\ ...

  5. 洛谷 P4512 [模板] 多项式除法

    题目:https://www.luogu.org/problemnew/show/P4512 看博客:https://www.cnblogs.com/owenyu/p/6724611.html htt ...

  6. 洛谷 P4238 [模板] 多项式求逆

    题目:https://www.luogu.org/problemnew/show/P4238 看博客:https://www.cnblogs.com/xiefengze1/p/9107752.html ...

  7. 洛谷P2293 高精开根

    锣鼓2293 写完了放代码 应该没什么思维难度 ———————————————————————————————————————————————————————— python真香 m=input() ...

  8. P5277 【模板】多项式开根(加强版)(bsgs or Cipolla)

    题面 传送门 题解 首先你得会多项式开根->这里 其次你得会解形如 \[x^2\equiv a \pmod{p}\] 的方程 这里有两种方法,一个是\(bsgs\)(这里),还有一种是\(Cip ...

  9. FFT模板 生成函数 原根 多项式求逆 多项式开根

    FFT #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> ...

  10. 洛谷P3373 [模板]线段树 2(区间增减.乘 区间求和)

    To 洛谷.3373 [模板]线段树2 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.将某区间每一个数乘上x 3.求出某区间每一个数的和 输入输出格式 输入格 ...

随机推荐

  1. shell 批量压缩指定目录及子目录内图片的方法

    用户上传的图片,一般都没有经过压缩,造成空间浪费.因此需要编写一个程序,查找目录及子目录的图片文件(jpg,gif,png),将大于某值的图片进行压缩处理. 查看目录文件大小 du -h --max- ...

  2. explain获得使用的key的数据

    bool Explain_join::explain_key_and_len() { if (tab->ref.key_parts) return explain_key_and_len_ind ...

  3. hdu1907John(反nim博弈)

    John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  4. 如何搭建本地svn服务器和搭建本地Git服务器

    搭建git本地服务器使用的软件有很多,例如:gitlab,gitblit,gitbucket,gogs,gitolite,具体比较:http://softlab.sdut.edu.cn/blog/su ...

  5. CodeForces - 1059D(二分+误差)

    链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...

  6. node事件循环

    Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...

  7. CSP201612-1:中间数

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  8. POJ - 3259

    要判断是否有负的权值 #include<iostream> #include<stdio.h> #include<algorithm> #include<st ...

  9. Laxcus大数据管理系统2.0(12)- 第十章 运行

    第十章 运行 本章将介绍一些Laxcus集群基本运行.使用情况,结合图片和表格表示.地点是我们的大数据实验室,使用我们的实验集群.数据来自于我们的合作伙伴,软件平台混合了Windows和Fedora  ...

  10. win32绘制自定义类窗口导致绘制11个窗口的解决办法

    上网查了一圈也没有找到解决问题的办法,一旦创建了一个窗口,并且在过程函数中绘制窗口,尤其是一些非子窗口的自定义类窗口,都会生成11个窗口(算上主窗口就是12个),但是使用系统通用控件就不会有这种情况的 ...