Polynomial to find inverse of template __ polynomial negation

Source: Internet
Author: User
Tags pow

The concrete concept and the method of solving the inverse element of polynomial see here, this article mainly provides templates.

This article provides a template that retains the 0~ N-n-th term, mod (xn+1) mod (x^{n+1}) under modulo 998244353.

#include <bits/stdc++.h> #define LL long-long using namespace std;
    int Getint () {int I=0,f=1;char C; For (C=getchar (); c!= '-' && (c< ' 0 ' | |
    C> ' 9 '); C=getchar ());
    if (c== '-') F=-1,c=getchar ();
    for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) i= (i<<3) + (i<<1) +c-' 0 ';
return i*f;
const int n=500005,p=998244353,g=3;

int n,a[n],b[n],pos[n],w[n],inv[n];
    int Pow (int x,int y) {int res=1;
    for (; y;y>>=1,x= (LL) x*x%p) if (y&1) res= (LL) res*x%p;
return res;
    } void Init () {int len=1,num=0;
        while (len< (n+1) <<1)) {len<<=1;
        W[++num]=pow (g, (p-1)/len);
    Inv[num]=pow (w[num],p-2); } void NTT (int f[],int len,int on) {for (int i=1;i<len;i++) pos[i]= (i&1)? pos[i>>1]>>1| (
    len>>1):p os[i>>1]>>1;
    for (int i=1;i<len;i++) if (I<pos[i]) swap (f[i],f[pos[i]); for (int i=1,num=1;i<len;i<<=1,num++) {int wn=(On==1?w[num]:inv[num]);
            for (int j=0;j<len;j+= (i<<1)) {int wi=1;
                for (int k=j;k<j+i;k++) {int u=f[k],v= (LL) wi*f[k+i]%p;
                f[k]= (u+v)%p,f[k+i]= (u-v+p)%p;
            Wi= (ll) wi*wn%p;
{}} if (On==-1) for (int i=0;i<len;i++) f[i]= (LL) F[i]*pow len,p-2 (%p);
        } void Poly_inv (int a[],int b[],int deg) {if (deg==1) {B[0]=pow (a[0],p-2);
    Return
    } POLY_INV (A,b, (deg+1) >>1);
    static int tmp[n];
    int len=1;
    while (len< (deg<<1)) len<<=1;
    for (int i=0;i<deg;i++) tmp[i]=a[i];
    for (int i=deg;i<len;i++) tmp[i]=0;
    for (int i= (deg+1) >>1;i<len;i++) b[i]=0;
    NTT (tmp,len,1), NTT (b,len,1);
    for (int i=0;i<len;i++) b[i]= (LL) b[i]* ((LL) tmp[i]*b[i]%p+p)%p)%p;
NTT (b,len,-1);
    int main () {//freopen ("lx.in", "R", stdin);
    N=getint ();
    Init (); for (int i=0;i<=n;i++) A[i]=getint ();
    POLY_INV (a,b,n+1);
    for (int i=0;i<=n;i++) cout<<b[i]<< ';
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.