QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740347#9619. 乘积,欧拉函数,求和nb_jzyWA 6ms4764kbC++201.5kb2024-11-13 09:15:082024-11-13 09:15:08

Judging History

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

  • [2024-11-13 09:15:08]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4764kb
  • [2024-11-13 09:15:08]
  • 提交

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,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++;
			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]=(prime[j]-1)*pro[i]%mod*ny[prime[j]]%mod;
			}
		}
	}
	int cntt=0;
	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++){
		sort(g[i].begin(),g[i].end());
		if(g[i].empty()){
			continue;
		}
		for(int j=0;j<=len;j++){
			f[j]=0;
		}
		for(auto v:g[i]){
			for(int j=len;j>0;j--){
				f[j|s[v]]=(f[j]*a[v]+f[j|s[v]])%mod;
			}
			f[s[v]]=(f[0]+1)*a[v]%mod;
		}
		int res=0;
		for(int j=0;j<=len;j++){
			res=(f[j]*pro[j]+res)%mod;
		}
		if(i>1){
			res=res*ny[i]%mod*(i-1)%mod;
		}
		ans=ans*(res+1)%mod;
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 4764kb

input:

5
1 6 8 6 2

output:

16

result:

wrong answer 1st lines differ - expected: '892', found: '16'