模板Code
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 998244353, g = 3, MAXN = 1<<18;
typedef long long LL; inline void change(int arr[], const int &len)
{
register int i, j, k;
for(i = 1, j = len/2; i < len-1; ++i)
{
if(i < j) swap(arr[i], arr[j]);
k = len/2;
while(j >= k) j -= k, k >>= 1;
j += k;
}
} inline int qmul(int a, int b, const int &c)
{
register int ret = 1;
while(b)
{
if(b&1) ret = (LL)ret * a % c;
a = (LL)a * a % c; b >>= 1;
}
return ret;
} inline void NTT(int arr[], const int &len, const int &flg)
{
change(arr, len);
register int wn, w, A0, wA1, i, j, k;
for(i = 2; i <= len; i <<= 1)
{
if(~flg) wn = qmul(g, (mod-1)/i, mod);
else wn = qmul(g, (mod-1) - (mod-1)/i, mod);
for(j = 0; j < len; j += i)
{
w = 1;
for(k = j; k < j + i/2; ++k)
{
A0 = arr[k], wA1 = (LL)w * arr[k + i/2]% mod;
arr[k] = (A0 + wA1) % mod;
arr[k + i/2] = ((A0 - wA1) % mod + mod) % mod;
w = (LL)w * wn % mod;
}
}
}
if(flg == -1)
{
register int rev = qmul(len, mod-2, mod);
for(i = 0; i < len; ++i)
arr[i] = (LL)arr[i] * rev % mod;
}
}
int a[MAXN], b[MAXN], c[MAXN]; void work(const int &deg, int a[], int b[])
{
if(deg == 1) { b[0] = qmul(a[0], mod-2, mod); return; }
work(deg+1>>1, a, b);
register int len = 1;
while(len < deg<<1) len <<= 1;
for(int i = 0; i < deg; ++i) c[i] = a[i];
for(int i = deg; i < len; ++i) c[i] = 0;
NTT(c, len, 1); NTT(b, len, 1);
for(int i = 0; i < len; ++i)
b[i] = (2 - (LL)b[i]*c[i]%mod + mod) % mod * b[i] % mod;
NTT(b, len, -1);
for(int i = deg; i < len; ++i) b[i] = 0;
}
int n;
void init()
{
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", &a[i]);
} void solve()
{
work(n, a, b);
for(int i = 0; i < n; ++i)
printf("%d%c", b[i], i == n-1 ? '\n' : ' ');
} int main ()
{
init(); solve();
}

多项式求逆入门 板题(Luogu P4238)的更多相关文章

  1. luogu P4725 多项式对数函数 (模板题、FFT、多项式求逆、求导和积分)

    手动博客搬家: 本文发表于20181125 13:25:03, 原地址https://blog.csdn.net/suncongbo/article/details/84487306 题目链接: ht ...

  2. 洛谷P4238【模板】多项式求逆

    洛谷P4238 多项式求逆:http://blog.miskcoo.com/2015/05/polynomial-inverse 注意:直接在点值表达下做$B(x) \equiv 2B'(x) - A ...

  3. 2018.12.30 洛谷P4238 【模板】多项式求逆

    传送门 多项式求逆模板题. 简单讲讲? 多项式求逆 定义: 对于一个多项式A(x)A(x)A(x),如果存在一个多项式B(x)B(x)B(x),满足B(x)B(x)B(x)的次数小于等于A(x)A(x ...

  4. [模板][P4238]多项式求逆

    NTT多项式求逆模板,详见代码 #include <map> #include <set> #include <stack> #include <cmath& ...

  5. P4238 【模板】多项式求逆

    思路 多项式求逆就是对于一个多项式\(A(x)\),求一个多项式\(B(x)\),使得\(A(x)B(x) \equiv 1 \ (mod x^n)\) 假设现在多项式只有一项,显然\(B(x)\)的 ...

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

    题目大意:多项式求逆 题解:$ A^{-1}(x) = (2 - B(x) * A(x)) \times B(x) \pmod{x^n} $ ($B(x)$ 为$A(x)$在$x^{\lceil \d ...

  7. hdu 5730 Shell Necklace [分治fft | 多项式求逆]

    hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治 ...

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

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

  9. BZOJ 3456: 城市规划 与 多项式求逆算法介绍(多项式求逆, dp)

    题面 求有 \(n\) 个点的无向有标号连通图个数 . \((1 \le n \le 1.3 * 10^5)\) 题解 首先考虑 dp ... 直接算可行的方案数 , 容易算重复 . 我们用总方案数减 ...

随机推荐

  1. 【转帖】HBase简介(梳理知识)

    HBase简介(梳理知识)   https://www.cnblogs.com/muhongxin/p/9471445.html 一. 简介 hbase是bigtable的开源山寨版本.是建立的hdf ...

  2. c# EF插入数据报错跟踪代码

    我们在使用EF进行数据库插入的时候或出现一些插入失败的情况,但是具体是哪个字段不符合数据库设计要求无法得知,普通的try catch 无法捕获加上一下方法就可以 try            {    ...

  3. Django使用distinct报错:DISTINCT ON fields is not supported by this database backend

    具体错误提示是:django.db.utils.NotSupportedError: DISTINCT ON fields is not supported by this database back ...

  4. HBase 系列(三)—— HBase 基本环境搭建

    一.安装前置条件说明 1.1 JDK版本说明 HBase 需要依赖 JDK 环境,同时 HBase 2.0+ 以上版本不再支持 JDK 1.7 ,需要安装 JDK 1.8+ .JDK 安装方式见本仓库 ...

  5. Java CookieUtils

    Java CookieUtils /** * <html> * <body> * <P> Copyright 1994 JsonInternational</ ...

  6. Redis Cluster: (error) MOVED

      I have a Redis cluster with the following nodes: 192.168.0.14:6379 master (slots from 0 to 16383) ...

  7. SSM前后端分离 ssm+html+js(ajax) 这种controll层的返回值是结合或者网址

    提示: 1.单表查询多条数据用 list<实体类名字> mapper层 1.1单表查询单条数据用  对象 2.两表关联查多条 list<map<String,Object> ...

  8. C# vb .net实现相机视图效果滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的相机视图效果呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第 ...

  9. python中configparser模块读取ini文件

    python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...

  10. 使用vue-router在页面之间传值及接收值

    第一页 点击去第二页的时候进行传值直接贴代码看: <template> <div id="app"> <div><router-link ...