当前位置:网站首页>NTT (fast number theory transformation) polynomial inverse 1500 word analysis
NTT (fast number theory transformation) polynomial inverse 1500 word analysis
2022-07-26 09:05:00 【Qin xiaobaa】
First of all, we have 
We are right. x^n Round up and open the root , namely 
We set up 
obviously 
Subtracting two formulas

so 
So the polynomial formed by subtraction is 0-
All to the power 0, Otherwise, they themselves cannot be
to be divisible by
Based on this finding
Square the subtraction


Multiply F(x) operation Again by

thus G(x) use NTT solve
# include<iostream>
using namespace std;
typedef long long int ll;
const int mod=998244353,g=3,N=2000000;
int n;
ll a[N],b[N],c[N],rev[N];
ll qp(ll base,ll pow)
{
ll ans=1;
while(pow)
{
if(pow&1)
ans=ans*base%mod;
pow>>=1;
base=base*base%mod;
}
return ans;
}
void init(int k)
{
int len=(1<<k);
for(int i=0;i<len;i++)
{
rev[i]=0;
}
for(int i=0;i<len;i++)
{
rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
}
return ;
}
void NTT(ll *a,int n,int flag)
{
for(int i=0;i<n;i++)
{
if(i<rev[i])
{
swap(a[i],a[rev[i]]);
}
}
for(int h=1;h<n;h<<=1)
{
ll gn=qp(3ll,(mod-1)/(h*2));
if(flag==-1)
gn=qp(gn,mod-2);
for(int j=0;j<n;j+=2*h)
{
ll gg=1;
for(int k=j;k<j+h;k++)
{
ll x=a[k];
ll y=gg*a[k+h]%mod;
a[k]=(x+y)%mod;
a[k+h]=((x-y)%mod+mod)%mod;
gg=gg*gn%mod;
}
}
}
if(flag==-1)
{
ll inv=qp(n,mod-2);
for(int i=0;i<n;i++)
{
a[i]=a[i]*inv%mod;
}
}
}
void work(int pow,ll*a,ll *b)
{
if(pow==1)
{
b[0]=qp(a[0],mod-2);
return ;
}
work((pow+1)>>1,a,b);
int k=1,s=2;
while((1<<k)<pow+pow-1)
{
k++;
s<<=1;
}
init(k);
for(int i=0;i<pow;i++)
{
c[i]=a[i];
}
/*
The reason to use c save a, Not right a The direct operation is because each time we recurse
Must be of the original sequence a
*/
NTT(c,s,1);
NTT(b,s,1);
for(int i=0;i<s;i++)
{
b[i]=(ll)(2ll-c[i]*b[i]%mod+mod)%mod*b[i]%mod;
}
NTT(b,s,-1);
for(int i=pow;i<s;i++)
{
b[i]=0;
}
return ;
}
int main ()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
work(n,a,b);
for(int i=0;i<n;i++)
{
cout<<b[i]<<" ";
}
return 0;
}
边栏推荐
- Media at home and abroad publicize that we should strictly grasp the content
- 围棋智能机器人阿法狗,阿尔法狗机器人围棋
- 十大蓝筹NFT近半年数据横向对比
- SQL入门——组合表
- ES6模块化导入导出)(实现页面嵌套)
- 布隆过滤器
- Learn more about the difference between B-tree and b+tree
- 堆外内存的使用
- 高数 | 武爷『经典系列』每日一题思路及易错点总结
- Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
猜你喜欢

Study notes of automatic control principle --- stability analysis of control system

Datax的学习笔记

Canal 的学习笔记

ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件
![[database] gbase 8A MPP cluster v95 installation and uninstall](/img/56/c0dae30ba608842c1b92e914ef42fe.png)
[database] gbase 8A MPP cluster v95 installation and uninstall

Node-v download and application, ES6 module import and export

Qtcreator reports an error: you need to set an executable in the custom run configuration

Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)

分布式跟踪系统选型与实践

(2006,Mysql Server has gone away)问题处理
随机推荐
机器学习中的概率模型
多项式开根
ext4文件系统打开了DIR_NLINK特性后,link_count超过65000的后使用link_count=1来表示数量不可知
Review notes of Microcomputer Principles -- zoufengxing
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi
The essence of attack and defense strategy behind the noun of network security
ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件
2022化工自动化控制仪表操作证考试题模拟考试平台操作
NFT与数字藏品到底有何区别?
谷粒学院的全部学习源码
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
ONTAP 9文件系统的限制
Web overview and b/s architecture
Day06 operation -- addition, deletion, modification and query
Uni app simple mall production
Rocky基础练习题-shell脚本2
对标注文件夹进行清洗
Grain College of all learning source code
李沐d2l(四)---Softmax回归
QtCreator报错:You need to set an executable in the custom run configuration.