QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737656#9619. 乘积,欧拉函数,求和monuiWA 7ms12864kbC++231.8kb2024-11-12 16:31:512024-11-12 16:31:51

Judging History

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

  • [2024-11-12 16:31:51]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:12864kb
  • [2024-11-12 16:31:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int M=998244353;
const int N=3010;

bool st[N][N];
int fac[N];
map<int,int> to;

int quick(int x,int n){
	int ans=1;
	while(n){
		if(n&1) ans=ans*x%M;
		x=x*x%M;
		n>>=1;
	}
	return ans;
}

void init(){
	int cnt=-1;
	for(int i=2;i<N;i++){
		bool flag=true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=false;
				break;
			}
		}
		if(flag){
			for(int j=i;j<N;j+=i){
				st[j][i]=true;
			}
			int t=(i-1)*quick(i,M-2)%M;
			if(i<=53) to[i]=++cnt,fac[cnt]=t;
			else fac[i]=t;
		}
	}
}

int n,a[N],val[N];
vector<vector<int>> q(N);

void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		bool flag=false;
		for(int j=2;j<N;j++){
			if(st[i][j]&&j<=53){
				val[i]|=(1ll<<to[j]);
			}
			else if(st[i][j]){
				q[j].push_back(i);
				flag=true;
			}
		}
		if(!flag) q[0].push_back(i);
	}
	vector<int> res(1ll<<16,0);res[0]=1;
	for(int p=0;p<q.size();p++){
		if(q[p].empty()) continue;
		int tt=fac[p];
		if(p==0) tt=1;
		vector<int> dp(1ll<<16,0);//中转,代表含有当前这个质因子的 
		for(auto& it:q[p]){
			//val[it]代表其状态,a[it]代表值 
			 for(int i=(1ll<<16)-1;i>=0;i--){
			 	int pp=1;
			 	for(int j=0;j<16;j++){
			 		if((1ll<<j&val[it])&&!(1ll<<j&i)){
			 			pp=pp*fac[j]%M;
					 }
				 }
				 int k=i|val[it];
				 if(dp[i]){
				 	dp[k]=(dp[k]+dp[i]*a[it]%M*pp%M)%M;
				 }
				 if(res[i]){
				 	dp[k]=(dp[k]+res[i]*a[it]%M*pp%M*tt%M)%M;
				 }
			 }
		}
		for(int i=0;i<(1ll<<16);i++) res[i]=(res[i]+dp[i])%M;
	}
	int ans=0;
	for(int i=0;i<(1ll<<16);i++) ans=(ans+res[i])%M;
	cout<<ans<<endl;
}

signed main(){
	std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int __T=1;
	init();
    //cin >> __T;
	while (__T--) solve();
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 12864kb

input:

5
1 6 8 6 2

output:

332748941

result:

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