QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#740322#9619. 乘积,欧拉函数,求和nb_jzyWA 252ms4812kbC++201.4kb2024-11-13 08:55:482024-11-13 08:55:54

Judging History

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

  • [2024-11-13 08:55:54]
  • 评测
  • 测评结果:WA
  • 用时:252ms
  • 内存:4812kb
  • [2024-11-13 08:55:48]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3005,maxs=17,mod=998244353;
int a[maxn],cnt=-1,id[maxn],n,len,f[1<<maxs],ny[maxn],s[maxn],prime[22],pro[1<<maxs];
vector<int> g[maxn];
int poww(int x,int y){
	int res=1;
	while(y>0){
		if(y&1){
			res=res*x%mod;
		}
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	for(int i=1;i<=3000;i++){
		ny[i]=poww(i,mod-2);
	}
	for(int i=2;i<=55;i++){
		bool f=1;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f=0;
				break;
			}
		}
		if(f){
			cnt++;
			id[i]=cnt;
			prime[cnt]=i;
		}
	}
	cnt++;
	cin>>n;
	int len=(1<<cnt)-1;
	for(int i=0;i<=len;i++){
		pro[i]=1;
		for(int j=0;j<cnt;j++){
			if((i>>j)&1){
				pro[i]=1ll*(prime[j]-1)*pro[i]%mod*ny[prime[j]]%mod;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
		int xx=a[i];
		for(int j=0;j<cnt;j++){
			while(xx%prime[j]==0){
				s[i]|=(1<<j);
				xx/=prime[j];
			}
		}
		g[xx].push_back(i);
	}
	int ans=1;
	for(int i=1;i<=3000;i++){
		if(g[i].empty()){
			continue;
		}
		for(int j=0;j<=len;j++){
			f[j]=0;
		}
		f[0]=1;
		for(auto v:g[i]){
			for(int j=len;j>=0;j--){
				f[j|s[v]]=(1ll*f[j]*a[v]+f[j|s[v]])%mod;
			}
		}
		int res=0;
		for(int j=0;j<=len;j++){
			res=(1ll*f[j]*pro[j]+res)%mod;
		}
		if(i>1){
			res=1ll*res*ny[i]%mod*(i-1)%mod;
		}
		ans=1ll*ans*res%mod;
	}
	cout<<ans;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 4764kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 6ms
memory: 4608kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 252ms
memory: 4812kb

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:

508601007

result:

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