QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737256#9619. 乘积,欧拉函数,求和kjhhjki#WA 484ms5752kbC++201.8kb2024-11-12 15:13:402024-11-12 15:13:42

Judging History

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

  • [2024-11-12 15:13:42]
  • 评测
  • 测评结果:WA
  • 用时:484ms
  • 内存:5752kb
  • [2024-11-12 15:13:40]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=(k);++i)
#define mod 998244353
#define MAXN 2005
typedef long long ll;
int n,rk,pri[MAXN],state[MAXN];
std::pair<int,int> a[MAXN];
ll ans,inv[MAXN],val[1<<16],f[1<<16],g[1<<16],tmp[1<<16];
inline bool chk(int x){
	rep(i,2,x-1) if(x%i==0) return false;
	return true;
}
inline void init(){
	rep(i,2,53) if(chk(i)) pri[++rk]=i;
}
inline ll pw(int x,int y){
	ll base=x,ret=1;
	for(;y;y>>=1,(base*=base)%=mod) if(y&1) (ret*=base)%=mod;
	return ret;
}
int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	std::cin>>n,init();
	rep(i,1,n) std::cin>>a[i].first,a[i].second=a[i].first;
	rep(i,1,n){
		rep(j,1,rk) if(a[i].first%pri[j]==0){
			state[i]|=1<<(j-1);
			while(a[i].first%pri[j]==0) a[i].first/=pri[j];
		}
	}
	rep(s,0,(1<<rk)-1){
		val[s]=1;
		rep(i,1,rk) if((s>>(i-1))&1) val[s]=val[s]*(pri[i]-1)%mod*pw(pri[i],mod-2)%mod;
	}
	rep(i,1,n) rep(j,1,n-1) if(a[j].first>a[j+1].first){
		std::swap(a[j].first,a[j+1].first);
		std::swap(state[j],state[j+1]);
	}
	rep(i,1,n) inv[i]=pw(a[i].first,mod-2);
	f[0]=1;
//	rep(i,1,n) std::cerr<<a[i].first<<' '<<a[i].second<<'\n';
	rep(i,0,n-1){
		int cur=i+1;
		while(a[cur+1].first==a[cur].first) ++cur;
		rep(s,0,(1<<rk)-1) tmp[s]=f[s];
		rep(j,i+1,cur){
			rep(s,0,(1<<rk)-1) g[s]=f[s];
			rep(s,0,(1<<rk)-1) f[s|state[j]]=(f[s|state[j]]+g[s]*a[j].second%mod*val[(s|state[j])^s])%mod;
		} 
//		rep(s,0,(1<<rk)-1) if(f[s]) std::cerr<<i<<' '<<s<<' '<<f[s]<<'\n';
        if(a[i+1].first>1){
        	rep(s,0,(1<<rk)-1) g[s]=f[s];
		    rep(s,0,(1<<rk)-1) f[s]=((g[s]-tmp[s]+mod)*(a[i+1].first-1)%mod*inv[i+1]+tmp[s])%mod;
		}
		i=cur-1;
//		rep(s,0,(1<<rk)-1) if(f[s]) std::cerr<<i<<' '<<s<<' '<<f[s]<<'\n';
	} 
	rep(s,0,(1<<rk)-1) ans+=f[s];
	std::cout<<ans%mod<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 63ms
memory: 5684kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 59ms
memory: 5728kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 484ms
memory: 5752kb

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:

22716483

result:

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