• 【TopCoder 11469】—Nim(Fwt)


    传送门


    NimNim游戏先手必败就是所有堆异或和为00

    kk个异或和为00就是FwtFwt点值kk次方
    把所有质数拿出来做一个FwtFwt就可以了

    #include<bits/stdc++.h>
    using namespace std;
    #define gc getchar
    inline int read(){
    	char ch=gc();
    	int res=0,f=1;
    	while(!isdigit(ch))f^=ch=='-',ch=gc();
    	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    	return f?res:-res;
    }
    #define re register
    #define pb push_back
    #define cs const
    #define pii pair<int,int>
    #define fi first
    #define se second
    #define ll long long
    cs int mod=1e9+7;
    inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
    inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
    inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
    inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
    inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
    inline void Mul(int &a,int b){a=mul(a,b);}
    inline int ksm(int a,int b,int res=1){
    	for(;b;b>>=1,a=mul(a,a))(b&1)&&(res=mul(res,a));return res;
    }
    inline void chemx(ll &a,ll b){a<b?a=b:0;}
    inline void chemn(int &a,int b){a>b?a=b:0;}
    cs int N=120005;
    int pr[N],tot;
    bitset<N> vis;
    inline void init(int n){
    	for(int i=2;i<=n;i++){
    		if(!vis[i])pr[++tot]=i;
    		for(int j=1;j<=tot&&pr[j]*i<=n;j++){
    			vis[i*pr[j]]=1;
    			if(i%pr[j]==0)break;
    		}
    	}
    }
    inline void Fwt(int *f,int lim,int kd){
    	for(int a0,a1,mid=1;mid<lim;mid<<=1){
    		for(int i=0;i<lim;i+=(mid<<1))
    		for(int j=0;j<mid;j++){
    			a0=f[i+j],a1=f[i+j+mid];
    			f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
    		}
    	}
    	if(kd==-1)for(int i=0,inv=ksm(lim,mod-2);i<lim;i++)Mul(f[i],inv);
    }
    int k,l;
    int a[N];
    class Nim{
    	public:
    	inline int count(int K,int L){
    		k=K,l=L;
    		int lim=1;
    		init(L);
    		while(lim<=pr[tot])lim<<=1;
    		for(int i=1;i<=tot;i++)a[pr[i]]=1;
    		Fwt(a,lim,1);
    		for(int i=0;i<lim;i++)a[i]=ksm(a[i],k);
    		Fwt(a,lim,-1);
    		return a[0];
    	}
    };
    
  • 相关阅读:
    bzoj2763: [JLOI2011]飞行路线(分层图spfa)
    8.20noip模拟题
    8.19noip模拟题
    1046: [HAOI2007]上升序列(dp)
    bzoj1079: [SCOI2008]着色方案(dp)
    逆序对
    P1966 火柴排队(逆序对)
    NOIP 2015 DAY2
    8.15学校模拟
    差分
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/12328692.html
Copyright © 2020-2023  润新知