• nowcoder73E 白兔的刁难 单位根反演+NTT


    感觉很套路?

    #include <bits/stdc++.h>  
    #define ll long long 
    #define setIO(s) freopen(s".in","r",stdin) 
    using namespace std;
    const int mod=998244353,G=3,SI=2000005; 
    inline int qpow(int x,int y) 
    {
        ll tmp=1;  
        for(;y;y>>=1,x=1ll*x*x%mod)    if(y&1)    tmp=1ll*tmp*x%mod;   
        return tmp;  
    }   
    inline int INV(int x) { return qpow(x,mod-2); }
    void NTT(int *a,int len,int flag) 
    {
        int i,j,k,mid;  
        for(i=k=0;i<len;++i) 
        {
            if(i>k)     swap(a[i],a[k]);  
            for(j=len>>1;(k^=j)<j;j>>=1);    
        }
        for(mid=1;mid<len;mid<<=1) 
        {
            int wn=qpow(G,(mod-1)/(mid<<1));   
            if(flag==-1)   wn=INV(wn);   
            for(i=0;i<len;i+=mid<<1) 
            {
                int w=1;  
                for(j=0;j<mid;++j) 
                {
                    int x=a[i+j],y=1ll*w*a[i+j+mid]%mod;   
                    a[i+j]=1ll*(x+y)%mod, a[i+j+mid]=1ll*(x-y+mod)%mod;   
                    w=1ll*w*wn%mod;   
                }
            }
        }
        if(flag==-1) 
        {
            int rev=INV(len);   
            for(i=0;i<len;++i)     a[i]=1ll*a[i]*rev%mod;   
        }
    }
    int K,A[SI];   
    char str[SI];  
    int main() 
    { 
        //    setIO("input");
        int i,j,now=0,len;     
        scanf(" %s%d",str+1,&K) ,len=strlen(str+1);   
        for(i=1;i<=len;++i)   now=(1ll*10*now%(mod-1)+str[i]-'0')%(mod-1);  
        int wn=qpow(G,(mod-1)/K),w=1;    
        for(i=0;i<K;++i)   A[i]=qpow(1+w,now),w=1ll*w*wn%mod;    
        NTT(A,K,-1);    
        ll tot=0ll;  
        for(i=0;i<K;++i)   tot^=A[i];  
        printf("%lld
    ",tot); 
        return 0; 
    }
    
  • 相关阅读:
    树链剖分( 洛谷P3384 )
    ZJOI 2015 诸神眷顾的幻想乡
    BZOJ 1002 [FJOI2007]轮状病毒
    洛谷 P1485 火枪打怪
    Luogu2860 [USACO06JAN]冗余路径Redundant Paths
    CF962F Simple Cycles Edges
    Luogu3605 [USACO17JAN]Promotion Counting晋升者计数
    Luogu2295 MICE
    CF341D Iahub and Xors
    CF617E XOR and Favorite Number
  • 原文地址:https://www.cnblogs.com/guangheli/p/11902004.html
Copyright © 2020-2023  润新知