当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Elastic APM安装和使用
Matlab 绘制阴影误差图
Flask project learning (I) -- sayhello
Database operation skills 7
day06 作业--增删改查
Datawhale panda book has been published!
Hegong sky team vision training Day6 - traditional vision, image processing
CF1481C Fence Painting
Probability model in machine learning
idea快捷键 alt实现整列操作
随机推荐
Matlab 绘制阴影误差图
Datawhale panda book has been published!
力扣刷题,三数之和
(2006,Mysql Server has gone away)问题处理
ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件
巴比特 | 元宇宙每日必读:元宇宙的未来是属于大型科技公司,还是属于分散的Web3世界?...
【无标题】
Set of pl/sql
C # use npoi to operate Excel
2022流动式起重机司机考试题模拟考试题库模拟考试平台操作
Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
Introduction to excellent verilog/fpga open source project (30) - brute force MD5
Elastic APM安装和使用
【LeetCode数据库1050】合作过至少三次的演员和导演(简单题)
redis原理和使用-基本特性
day06 作业---技能题7
187. Repeated DNA sequence
PAT 甲级 A1034 Head of a Gang
《Datawhale熊猫书》出版了!
PHP 之 Apple生成和验证令牌