QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747073 | #9619. 乘积,欧拉函数,求和 | yzhang# | WA | 15ms | 4112kb | C++23 | 2.4kb | 2024-11-14 16:16:55 | 2024-11-14 16:16:56 |
Judging History
answer
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int power(int a,int b){
int res=1;
while(b){
if(b&1) res=1ll*res*a%mod;
a=1ll*a*a%mod,b>>=1;
}
return res;
}
int n;
struct node{
int v,m;
}a[2005];
bool cmp(node a,node b){
return a.m<b.m;
}
int pr[3005],phi[3005],mxpr[3005];
int msk[3005],val[1<<15];
int p[20]={2,3,5,7,11 ,13,17,19,23,29 ,31,37,41,43,47};
int invp[20];
void init(){
for(int i=2;i<=3000;++i){
pr[i]=1;
for(int j=2;j<i;++j)
if(i%j==0)
pr[i]=0;
}
for(int i=2;i<=3000;++i){
for(int j=i;j>=2;--j)
if(i%j==0&&pr[j]){
mxpr[i]=j;
break;
}
}
for(int i=1;i<=3000;++i)
for(int j=0;j<=14;++j)
if(i%p[j]==0)
msk[i]|=(1<<j);
for(int i=0;i<=14;++i) invp[i]=power(p[i],mod-2);
for(int i=0;i<(1<<15);++i){
val[i]=1;
for(int j=0;j<=14;++j)
if(i&(1<<j))
val[i]=1ll*val[i]*(p[j]-1)%mod*invp[j]%mod;
}
}
int f[1<<15],g[1<<15],h[1<<15];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int blk=53;
init();
cin>>n;
for(int i=1;i<=n;++i){
cin>>a[i].v;
a[i].m=mxpr[a[i].v];
}
sort(a+1,a+1+n,cmp);
f[0]=1;
for(int i=1,j=1;i<=n;i=j+1){
while(j+1<=n&&a[j+1].m==a[i].m) ++j;
memset(g,0,sizeof(g));
for(int k=i;k<=j;++k){
memset(h,0,sizeof(h));
//case 1
int mul=1;
if(a[i].m>=blk){
mul=1ll*(a[i].m-1)*power(a[i].m,mod-2)%mod;
}
for(int ms=0;ms<(1<<15);++ms){
h[ms|msk[a[k].v]]=(0ll+h[ms|msk[a[k].v]]+1ll*f[ms]*a[k].v%mod*val[ms^(ms|msk[a[k].v])]%mod*mul%mod)%mod;
}
//case 2
for(int ms=0;ms<(1<<15);++ms){
h[ms|msk[a[k].v]]=(0ll+h[ms|msk[a[k].v]]+1ll*g[ms]*a[k].v%mod*val[ms^(ms|msk[a[k].v])]%mod)%mod;
}
for(int ms=0;ms<(1<<15);++ms) g[ms]=h[ms];
}
for(int ms=0;ms<(1<<15);++ms) f[ms]=(0ll+f[ms]+g[ms])%mod;
}
int ans=0;
for(int ms=0;ms<(1<<15);++ms) ans=(0ll+ans+f[ms])%mod;
cout<<ans<<'\n';
return 0;
}
/*
2 3 5 7 11
13 17 19 23 29
31 37 41 43 47
53?
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 4112kb
input:
5 1 6 8 6 2
output:
552
result:
wrong answer 1st lines differ - expected: '892', found: '552'