QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740439#9619. 乘积,欧拉函数,求和jr_zchWA 631ms219752kbC++141.6kb2024-11-13 09:56:192024-11-13 09:56:27

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 09:56:27]
  • 评测
  • 测评结果:WA
  • 用时:631ms
  • 内存:219752kb
  • [2024-11-13 09:56:19]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxn=3e3+7,maxp=5e2+7,maxs=1<<16,mod=998244353;
const int p[60]={0,2,3,5,7,11,13,17,23,29,31,37,41,43,47,51,53};
int n,ans;
int a[maxn],w[maxn],f[maxp][maxs],g[maxs],h[maxs];
vector<int> big;
vector<int> e[maxn];

/*
f[i+1][s] <- f[i][s]
f[i+1][s^w[i+1]] <- f[i][s]*a[i+1]
*/

int _mod(int x){
	return x>=mod?x-mod:x;
}

int qpow(int x,int y){
	if(!y) return 1;
	if(y==1) return x;
	int val=qpow(x,y>>1ll);
	if(y&1ll) return val*val%mod*x%mod;
	else return val*val%mod;
}

void calc(int x){
	int now=x;
	for(int i=1;i<=16;i++){
		if(!(now%p[i])){
			w[x]|=1<<i-1;
			while(!(now%p[i])) now/=p[i]; 
		}
	}
	e[now].push_back(x);
	big.push_back(now);
	return ;
}

signed main(){
	for(int s=0;s<maxs;s++){
		h[s]=1;
		for(int i=0;i<16;i++){
			if(s&1<<i) h[s]=h[s]*(p[i+1]-1)%mod*qpow(p[i+1],mod-2)%mod;
		}
	}
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),calc(a[i]);
	sort(big.begin(),big.end());
	big.erase(unique(big.begin(),big.end()),big.end());
	int tot=big.size();
	f[0][0]=1;
	
	for(int i=0;i<tot;i++){
		int num=big[i];
		int mul=(num-1)*qpow(num,mod-2)%mod;
		if(num==1) mul=1;
		for(int s=0;s<maxs;s++) g[s]=0;
		for(int j=0;j<e[num].size();j++){
			int val=e[num][j];
			for(int s=maxs-1;s>=0;s--){
				g[s|w[val]]=(g[s|w[val]]+g[s]*val%mod+f[i][s]*val%mod*mul%mod)%mod;
			}
		}
		for(int s=0;s<maxs;s++) f[i+1][s]=g[s];
	}
	
	for(int s=0;s<maxs;s++) ans=(ans+f[tot][s]*h[s])%mod;
	printf("%lld",ans+1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 101ms
memory: 6004kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 105ms
memory: 6336kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 631ms
memory: 219752kb

input:

2000
79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...

output:

720215449

result:

wrong answer 1st lines differ - expected: '50965652', found: '720215449'