P5277 【模板】多项式开根(加强版)

P5277 【模板】多项式开根(加强版)
在这里插入图片描述
这题好像没有a0=0的数据。

以下二次剩余使用mod以内较小的那个解。

(一)利用B2=A 得到 B=A1/2 利用多项式的幂计算。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#define ll long long
#define llu unsigned ll
using namespace std;
const int maxn=8e5+100;
const int p=998244353;
const int mod=998244353;
const int g=3;

struct erCi
{
   
    struct node
    {
   
        ll x,y;
        node(){
   }
        node(ll a,ll b)
        {
   
            x=a,y=b;
        }
    };

    node mul(const node &a,const node &b,const ll &w,const ll &p)
    {
   
        node ans;
        ans.x=((a.x*b.x%p+a.y*b.y%p*w%p)%p+p)%p;
        ans.y=((a.x*b.y%p+a.y*b.x%p)+p)%p;
        return ans;
    }

    ll mypow(ll a,ll b,ll p)
    {
   
        ll ans=1;
        while(b)
        {
   
            if(b&1) ans=ans*a%p;
            a=a*a%p;
            b>>=1;
        }
        return ans;
    }

    ll mypow(node a,ll b,ll w,ll p)
    {
   
        node ans=node(1,0);
        while(b)
        {
   
            if(b&1) ans=mul(ans,a,w,p);
            a=mul(a,a,w,p);
            b>>=1;
        }
        return ans.x%p;
    }

    ll fi(ll n,ll p=mod)
    {
   
        n%=p;
        if(p==2) return n;
        if(mypow(n,(p-1)/2,p)==p-1) return -1;
        ll a,w;
        while(1)
        {
   
            a=rand()%p;
            w=((a*a%p-n)%p+p)%p;
            if(mypow(w,(p-1)/2,p)==p-1) break;
        }
        node ans=node(a,1);
        ll res=mypow(ans,(p+1)/2,w,p);
        return min(res,p-res);
    }
}er;


int fi[maxn];
int a[maxn],inva[maxn],da[maxn],lna[maxn],c[maxn],iinv[maxn];
int f[maxn];
int n;

void get_inv(int n)
{
   
    iinv[1]=1;
    for(int i=2;i<=n;i++)
        iinv[i]=1ll*(mod-mod/i)*iinv[mod%i]%mod;
}

int mypow(int a,int b)
{
   
    if(b<0) return mypow(mypow(a,p-2),-b);
    int ans=1;
    while(b)
    {
   
        if(b&1) ans=1ll*ans*a%p;
        a=1ll*a*a%p;
        b>>=1;
    }
    return ans%p;
}

int getlen(int n,int m)//n,m是次数
{
   
    int len=1,cnt=0;
    while(len<=n+m) len<<=1,cnt
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值