当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Unity topdown character movement control

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

李沐d2l(五)---多层感知机

209. Subarray with the smallest length

2022茶艺师(中级)特种作业证考试题库模拟考试平台操作

Introduction to excellent verilog/fpga open source project (30) - brute force MD5

idea快捷键 alt实现整列操作

pycharm 打开多个项目的两种小技巧

Zipkin安装和使用

day06 作业--技能题6
随机推荐
Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points
2022化工自动化控制仪表操作证考试题模拟考试平台操作
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
(1) CTS tradefed test framework environment construction
李沐d2l(六)---模型选择
数据库操作 技能6
Center an element horizontally and vertically
第6天总结&数据库作业
unity简易消息机制
PAT 甲级 A1034 Head of a Gang
深度学习常用激活函数总结
Pat grade a a1076 forwards on Weibo
Hegong sky team vision training Day6 - traditional vision, image processing
SQL入门——组合表
[leetcode database 1050] actors and directors who have cooperated at least three times (simple question)
多项式开根
MySQL 强化知识点
数据库操作 题目一
Day 6 summary & database operation
Database operation topic 2