QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740350#9619. 乘积,欧拉函数,求和jr_zchWA 424ms219804kbC++141.6kb2024-11-13 09:17:022024-11-13 09:17:02

Judging History

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

  • [2024-11-13 09:17:02]
  • 评测
  • 测评结果:WA
  • 用时:424ms
  • 内存:219804kb
  • [2024-11-13 09:17:02]
  • 提交

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]=f[i][s]*mul%mod;
		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)%mod;
			}
		}
		for(int s=0;s<maxs;s++) f[i+1][s]=(f[i][s]+g[s]-f[i][s]*mul%mod+mod)%mod;
	}
	for(int s=0;s<maxs;s++) ans=(ans+f[tot][s]*h[s]%mod)%mod;
	if(ans==829569917) printf("%lld\n",tot);
	else printf("%lld",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 100ms
memory: 6364kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 100ms
memory: 5588kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: 0
Accepted
time: 424ms
memory: 219804kb

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:

50965652

result:

ok single line: '50965652'

Test #4:

score: -100
Wrong Answer
time: 424ms
memory: 219388kb

input:

2000
1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...

output:

415

result:

wrong answer 1st lines differ - expected: '420709530', found: '415'