One problem polynomial - inverse polynomial

problem:

Is known as a number $ n-1 $ polynomial $ F (x) $, find a polynomial $ G (x) $ such that $ F (x) * G (x) \ equiv 1 $ ($ mod x ^ {n } $), all operations carried out in the sense die 998 244 353

How do?

To be a little analysis:

If $ F (x) $ is only one, then $ G (x) $ in only one, that is, $ F (x) $ in terms of the inverse of that

Then if we know a polynomial $ H (x) $ satisfies $ F (x) * H (x) \ equiv 1 $ ($ mod $ $ x ^ {\ frac {n} {2}} $)

Obviously, according to requirements, while: $ F (x) * G (x) \ equiv 1 $ ($ mod $ $ x ^ {\ frac {n} {2}} $)

Save the formula formula, to give:

$F(x)(G(x)-H(x))\equiv 0$($mod$ $x^{\frac{n}{2}}$)

 Then there

$G(x)-H(x)\equiv 0$($mod$ $x^{\frac{n}{2}}$)

Both sides of the square can be obtained:

$(G(x)-H(x))^{2}\equiv 0$ ($mod$ $x^{n}$)

Expanded, too:

$G(x)^{2}+H(x)^{2}-2G(x)H(x)\equiv 0$($mod$ $x^{n}$)

Both sides take a $ F (x) $, are:

$F(x)G(x)^{2}+F(x)H(x)^{2}-2F(x)G(x)H(x)\equiv 0$($mod$ $x^{n}$)

According to requirements, $ F (x) G (x) \ equiv 1 $ ($ mod $ $ x ^ {n} $)

So the equation can be simplified to:

$G(x)+F(x)H(x)^{2}-2H(x)\equiv 0$($mod$ $x^{n}$)

Transposition, gives:

$G(x)\equiv 2H(x)-F(x)H(x)^{2}$ ($mod$ $x^{n}$)

This can be solved doubled

Code:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#define ll long long
using namespace std;
const ll mode=998244353;
ll f[100005];
int to[(1<<20)+5];
struct node
{
    ll g[100005];
    int len;
}now,las;
int n;
int lim=1,l=0;
ll pow_mul(ll x,ll y)
{
    ll ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%mode;
        x=x*x%mode,y>>=1;
    }
    return ret;
}
void NTT(ll *a,int len,int k)
{
    ll inv=pow_mul(len,mode-2);
    for(int i=0;i<len;i++)if(i<to[i])swap(a[i],a[to[i]]);
    for(int i=1;i<len;i<<=1)
    {
        ll w0=pow_mul(3,(mode-1)/(i<<1));
        for(int j=0;j<len;j+=(i<<1))
        {
            ll w=1;
            for(int o=0;o<i;o++,w=w*w0%mode)
            {
                ll w1=a[j+o],w2=a[j+o+i]*w%mode;
                a[j+o]=(w1+w2)%mode,a[j+o+i]=((w1-w2)%mode+mode)%mode;
            }
        }
    }
    if(k==-1)
    {
        for(int i=1;i<(len>>1);i++)swap(a[i],a[len-i]);
        for(int i=0;i<len;i++)a[i]=a[i]*inv%mode;
    }
}
ll a[(1<<20)+5],b[(1<<20)+5],c[(1<<20)+5];
void solve(int dep)
{
    if(dep==1)
    {
        now.g[0]=pow_mul(f[0],mode-2);
        now.len=1;
        las=now;
        return;
    }
    int nxt=(dep+1)/2;
    solve(nxt);
    lim=1,l=0;
    while(lim<=2*dep)lim<<=1,l++;
    for(int i=1;i<lim;i++)to[i]=((to[i>>1]>>1)|((i&1)<<(l-1)));
    for(int i=0;i<lim;i++)a[i]=b[i]=0;
    for(int i=0;i<dep;i++)a[i]=f[i];
    for(int i=0;i<nxt;i++)b[i]=las.g[i];
    NTT(a,lim,1),NTT(b,lim,1);
    for(int i=0;i<lim;i++)c[i]=a[i]*b[i]%mode*b[i]%mode;
    NTT(c,lim,-1);
    now.len=dep;
    for(int i=0;i<dep;i++)now.g[i]=((2*las.g[i]-c[i])%mode+mode)%mode;
    las=now;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lld",&f[i]);
    solve(n);
    for(int i=0;i<n;i++)printf("%lld ",now.g[i]);
    printf("\n");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/zhangleo/p/11007428.html