手动博客搬家: 本文发表于20181127 08:39:42, 原地址https://blog.csdn.net/suncongbo/article/details/84559818

题目链接: https://www.luogu.org/problem/show?pid=4726

题意: 给定\(n\)次多项式\(A(x)\) 求多项式\(f(x)\)满足\(f(x)\equiv e^{A(x)} (\mod x^n)\)

题解

这个比对数函数复杂一些。。

前铺知识

泰勒展开

对于一个函数,我们可以用以下方式用它的高阶导数进行无穷逼近:

\[f(x)=f(a)+f'(a)(x-a)+f''(a)\frac{(x-a)^2}{2!}+f'''(a)\frac{(x-a)^3}{3!}+...
\]

牛顿迭代

已知要求的多项式\(f\)满足\(g(f(x))\equiv 0(\mod x^n)\) \(g\)已知,那么可以通过如下的方式倍增求解:

假设求出了原问题\(\mod x^n\)的答案\(f_0(x)\), 考虑转移到\(f(x) \mod x^{2n}\).

根据泰勒展开公式: $$0=g(f)=g(f_0)+g'(f_0)(f-f_0)+g''(f_0)\frac{(f-f_0)^2}{2!}+...$$

但是,由于一个显然的结论——\(f\equiv f_0(\mod x^n)\), 因此\((f-f_0)^2\equiv 0(\mod x^{2n})\), 因此公式里只需要计算前两项,后面的项都在\(\mod x^{2n}\)意义下为\(0\)!

即\(g(f_0)+g'(f_0)(f-f_0)=0\)

\(f=f_0-\frac{g(f_0)}{g'(f_0)}\)

如此即可求解。

本题题解

根据牛顿迭代的法则,令\(g(f)=\ln f-A\), 则\(f=f_0-\frac{\ln f_0-A}{\frac{1}{f_0}}=f_0(1-\ln f_0+A)\)

递归求解即可。

值得注意的是FFT的大小

\(A\)应该带入\(2n\)次, \(\ln f_0\)应该带入\(2n\)次, \(f_0\)应该带入\(n\)次, FFT乘法因为是\(2n\)次乘以\(n\)次,所以应该取到\(4n\)个单位根。

FFT这个地方太容易出错了!范围大了常数大好几倍,范围小了就会出错。

时间复杂度为\(T(n)=T(\frac{n}{2})+O(n\log n)\), \(T(n)=O(n\log n)\)

常数我算的应该是\(48\)倍。每次\(n\)到\(2n\)的迭代需要做一次\(2n\)的\(\ln\)和三次\(4n\)的DFT/IDFT. 因此\(18(2n\log n)+3(4n\log n)=48n\log n\).

(飞了……)

代码

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std; const int N = 1<<19;
const int LGN = 19;
const int G = 3;
const int P = 998244353;
llong tmp1[N+3],tmp2[N+3],tmp3[N+3],tmp4[N+3]; //inv
llong tmp5[N+3],tmp6[N+3],tmp7[N+3],tmp8[N+3]; //ln
llong tmp9[N+3],tmp10[N+3],tmp11[N+3],tmp12[N+3]; //exp
llong a[N+3],b[N+3];
int id[N+3];
int n; llong quickpow(llong x,llong y)
{
llong cur = x,ret = 1ll;
for(int i=0; y; i++)
{
if(y&(1ll<<i))
{
ret = ret*cur%P;
y-=(1ll<<i);
}
cur = cur*cur%P;
}
return ret;
}
llong mulinv(llong x) {return quickpow(x,P-2);} void initid(int dgr)
{
int len = 0;
for(int i=0; i<=LGN; i++) if(dgr==(1<<i)) {len = i; break;}
id[0] = 0;
for(int i=1; i<dgr; i++) id[i] = (id[i>>1]>>1)|((i&1)<<(len-1));
} void ntt(int dgr,int coe,llong poly[],llong ret[])
{
initid(dgr);
for(int i=0; i<dgr; i++) ret[i] = poly[i];
for(int i=0; i<dgr; i++) if(i<id[i]) swap(ret[i],ret[id[i]]);
for(int i=1; i<=(dgr>>1); i<<=1)
{
llong tmp = quickpow(G,(P-1)/(i<<1));
if(coe==-1) tmp = mulinv(tmp);
for(int j=0; j<dgr; j+=(i<<1))
{
llong expn = 1ll;
for(int k=0; k<i; k++)
{
llong x = ret[j+k],y = ret[j+k+i]*expn%P;
ret[j+k] = x+y; modinc(ret[j+k]);
ret[j+i+k] = x-y+P; modinc(ret[j+i+k]);
expn = (expn*tmp)%P;
}
}
}
if(coe==-1)
{
llong tmp = mulinv(dgr);
for(int j=0; j<dgr; j++) ret[j] = ret[j]*tmp%P;
}
} void polyinv(int dgr,llong poly[],llong ret[])
{
for(int i=0; i<dgr; i++) ret[i] = 0ll;
ret[0] = mulinv(poly[0]);
for(int i=1; i<=(dgr>>1); i<<=1)
{
for(int j=0; j<(i<<2); j++) tmp1[j] = j<i ? ret[j] : 0ll;
for(int j=0; j<(i<<2); j++) tmp2[j] = j<(i<<1) ? poly[j] : 0ll;
ntt((i<<2),1,tmp1,tmp3); ntt((i<<2),1,tmp2,tmp4);
for(int j=0; j<(i<<2); j++) tmp3[j] = tmp3[j]*tmp3[j]%P*tmp4[j]%P;
ntt((i<<2),-1,tmp3,tmp4);
for(int j=0; j<(i<<1); j++) ret[j] = (tmp1[j]+tmp1[j]-tmp4[j]+P)%P;
}
for(int i=dgr; i<(dgr<<1); i++) ret[i] = 0ll;
} void polyder(int dgr,llong poly[],llong ret[])
{
for(int i=0; i<dgr-1; i++) ret[i] = poly[i+1]*(i+1)%P;
} void polyint(int dgr,llong poly[],llong ret[])
{
for(int i=1; i<dgr; i++) ret[i] = poly[i-1]*mulinv(i)%P;
} void polyln(int dgr,llong poly[],llong ret[])
{
for(int i=0; i<dgr; i++) ret[i] = 0ll;
polyder(dgr,poly,tmp5);
polyinv(dgr,poly,tmp6);
ntt((dgr<<1),1,tmp5,tmp7); ntt((dgr<<1),1,tmp6,tmp8);
for(int i=0; i<(dgr<<1); i++) tmp7[i] = tmp7[i]*tmp8[i]%P;
ntt((dgr<<1),-1,tmp7,tmp8);
polyint(dgr,tmp8,ret);
} void polyexp(int dgr,llong poly[],llong ret[])
{
for(int i=0; i<dgr; i++) ret[i] = i==0;
for(int i=1; i<=(dgr>>1); i<<=1)
{
for(int j=0; j<(i<<2); j++) tmp9[j] = j>=(i<<1) ? 0ll : ((j==0)+poly[j])%P;
for(int j=0; j<(i<<2); j++) tmp10[j] = j>=i ? 0ll : ret[j];
polyln((i<<1),tmp10,tmp11);
for(int j=0; j<(i<<1); j++) {tmp9[j] = tmp9[j]-tmp11[j]+P; modinc(tmp9[j]);}
ntt((i<<2),1,tmp10,tmp12); ntt((i<<2),1,tmp9,tmp11);
for(int j=0; j<(i<<2); j++) tmp12[j] = tmp12[j]*tmp11[j]%P;
ntt((i<<2),-1,tmp12,tmp11);
for(int j=0; j<(i<<1); j++) ret[j] = tmp11[j];
}
} int main()
{
scanf("%d",&n); int dgr = 1; while(dgr<=n) dgr<<=1;
for(int i=0; i<n; i++) scanf("%lld",&a[i]);
polyexp(dgr,a,b);
for(int i=0; i<n; i++) printf("%lld ",b[i]);
return 0;
}

luogu P4726 多项式指数函数(模板题FFT、多项式求逆、多项式对数函数)的更多相关文章

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

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

  2. 【BZOJ3456】轩辕朗的城市规划 无向连通图计数 CDQ分治 FFT 多项式求逆 多项式ln

    题解 分治FFT 设\(f_i\)为\(i\)个点组成的无向图个数,\(g_i\)为\(i\)个点组成的无向连通图个数 经过简单的推导(枚举\(1\)所在的连通块大小),有: \[ f_i=2^{\f ...

  3. bzoj 3456 城市规划——分治FFT / 多项式求逆 / 多项式求ln

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3456 分治FFT: 设 dp[ i ] 表示 i 个点时连通的方案数. 考虑算补集:连通的方 ...

  4. NTT+多项式求逆+多项式开方(BZOJ3625)

    定义多项式$h(x)$的每一项系数$h_i$,为i在c[1]~c[n]中的出现次数. 定义多项式$f(x)$的每一项系数$f_i$,为权值为i的方案数. 通过简单的分析我们可以发现:$f(x)=\fr ...

  5. 2019.01.01 bzoj3625:小朋友和二叉树(生成函数+多项式求逆+多项式开方)

    传送门 codeforces传送门codeforces传送门codeforces传送门 生成函数好题. 卡场差评至今未过 题意简述:nnn个点的二叉树,每个点的权值KaTeX parse error: ...

  6. [Codeforces438E][bzoj3625] 小朋友和二叉树 [多项式求逆+多项式开根]

    题面 传送门 思路 首先,我们把这个输入的点的生成函数搞出来: $C=\sum_{i=0}^{lim}s_ix^i$ 其中$lim$为集合里面出现过的最大的数,$s_i$表示大小为$i$的数是否出现过 ...

  7. P6295-有标号 DAG 计数【多项式求逆,多项式ln】

    正题 题目链接:https://www.luogu.com.cn/problem/P6295 题目大意 求所有\(n\)个点的弱联通\(DAG\)数量. \(1\leq n\leq 10^5\) 解题 ...

  8. UVA 796 Critical Links(模板题)(无向图求桥)

    <题目链接> 题目大意: 无向连通图求桥,并将桥按顺序输出. 解题分析: 无向图求桥的模板题,下面用了kuangbin的模板. #include <cstdio> #inclu ...

  9. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

随机推荐

  1. luogu2024 食物链

    题目大意 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B吃 C,C 吃 A.现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种,但是我们并 ...

  2. oc52--autorelease1

    // // main.m /* autorelease也是用于内存管理的,给对象发送autorelease消息就会把对象放入autoreleasepool这个池子中,当池子销毁的时候会对池子里面的所有 ...

  3. C语言/C++中如何产生随机数

    C语言/C++中如何产生随机数 作者: 字体:[增加 减小] 类型:转载 时间:2013-10-14我要评论 这里要用到的是rand()函数, srand()函数,和time()函数.需要说明的是,i ...

  4. android recovery 主系统代码分析【转】

    本文转载自:http://blog.csdn.net/andyhuabing/article/details/9248713 阅读完上一篇文章: http://blog.csdn.net/andyhu ...

  5. 杂项-人物:Alan cooper

    ylbtech-杂项-人物:Alan cooper Alan Cooper ,“VB之父”“交互设计之父”,荣获视窗先锋奖(Microsoft Windows Pioneer)和软件梦幻奖(Softw ...

  6. Cent OS 6/7 中通过yum安装软件时提示cannot find a valid baseurl...的解决方法

    目录 1 问题描述 2 解决方法一 (Cent OS 7中有效) 3 解决方法二 (Cent OS 7中无效) 1 问题描述 新申请了虚拟机, 系统版本是Cent OS 7.2. 在安装软件的过程中, ...

  7. Android Gradle 学习笔记(七):Android Gradle 插件

    我们知道Android Gradle其实就是一个Gradle的一个第三方插件,它是由Google的Android团队开发的,基于Gradle构建的,和Android Studio完美搭配.相比于旧的构 ...

  8. html与css命名规范小结

    一.命名规则说明 所有的命名最好都用小写 使用英文命名 给每一个表格和表单加上一个唯一的.结构标记id 给每个图片加上alt标签,优点在于图片发生错误时,alt可以体现给用户 二.相对网页外层重要部分 ...

  9. 【Linux】七种文件类型

    Linux中的七种文件类型 d 目录文件. l 符号链接(指向另一个文件). s 套接字文件. b 块设备文件,二进制文件. c 字符设备文件. p 命名管道文件. - 普通文件

  10. Linux scp 后台运行传输文件

    Linux scp 设置nohup后台运行 1.正常执行scp命令 2.输入ctrl + z 暂停任务 3.bg将其放入后台 4.disown -h 将这个作业忽略HUP信号 5.测试会话中断,任务继 ...