QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#737066 | #9619. 乘积,欧拉函数,求和 | kjhhjki# | WA | 62ms | 5656kb | C++20 | 1.7kb | 2024-11-12 14:31:42 | 2024-11-12 14:31:42 |
Judging History
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,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;
}
std::sort(a+1,a+n+1),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*pw(a[i+1].first,mod-2)+tmp[s])%mod;
}
i=cur-1;
// rep(s,0,(1<<rk)-1) if(f[s]) std::cerr<<i<<' '<<s<<'\n';
}
rep(s,0,(1<<rk)-1) ans+=f[s];
std::cout<<ans%mod<<'\n';
}
详细
Test #1:
score: 0
Wrong Answer
time: 62ms
memory: 5656kb
input:
5 1 6 8 6 2
output:
904
result:
wrong answer 1st lines differ - expected: '892', found: '904'