调很久了,求求大佬 hack!!!
查看原帖
调很久了,求求大佬 hack!!!
182691
SisconHL楼主2020/10/22 17:33
#include<cstdio>
#define int long long
using namespace std;
const int nmax=(1<<18);
const int mod=1e9+7;
int bin[nmax],DP[nmax];bool b[nmax];
int phi[nmax],prime[nmax],p=0;
void getphi(){
	for(int i=2;i<nmax;i++){
		if(!phi[i]) prime[p++]=i,phi[i]=i-1;
		for(int j=0;j<p&&prime[j]*i<=nmax;j++){
            if(i%prime[j])phi[prime[j]*i]=(prime[j]-1)*phi[i];
            else{phi[prime[j]*i]=prime[j]*phi[i];break;}
        }
	}
}
int qpow(int x){
	if(x<2)return x+1;
	int res=qpow(x/2)%mod,f=(x&1)+1;
	return res*res%mod*f%mod;
}
int dp(int x){
	if(b[x])return DP[x];b[x]=true;
	for(int s=x;(s^x)<s;s=(s-1)&x)DP[x]+=DP[s^x]*bin[s],DP[x]%=mod;
	return DP[x]*phi[x+1]%mod;
} 
signed main(){
	for(int i=0;i<nmax;i++)b[i]=!i,bin[i]=0;
	int n,x,ans=1;scanf("%lld",&n);phi[1]=1;b[0]=true;getphi();
	for(int i=0;i<n;i++)scanf("%lld",&x),bin[x]++;
	DP[0]=1;for(int i=1;i<nmax;i++)ans+=dp(i),ans%=mod;
	printf("%lld",ans*qpow(bin[0]));return 0;
}

#1 AC,其他WA

2020/10/22 17:33
加载中...