QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746324#9619. 乘积,欧拉函数,求和Qzong#WA 8ms2924kbC++142.2kb2024-11-14 14:14:462024-11-14 14:14:46

Judging History

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

  • [2024-11-14 14:14:46]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:2924kb
  • [2024-11-14 14:14:46]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
const int N=3020;
const int mod=998244353;
int n;
int pri[N],tot,k[N],id[N],mx[N],f[2][1<<17|10];
struct node{
    int val,mx;
    bool operator<(const node &A)const {
        return mx<A.mx;
    }
}a[N];
int ad(int x,int y){
    return x+y>=mod?x+y-mod:x+y;
}
int ksm(int x,int y){
    int ans=1;
    while(y){
        if(y&1)ans=1ll*ans*x%mod;
        x=1ll*x*x%mod;
        y>>=1;
    }
    return ans;
}
int inv[N],go[1<<17|10];
int main(){
    // freopen("a.in","r",stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].val);
    for(int i=1;i<=3000;i++)inv[i]=ksm(i,mod-2);
    for(int i=2;i<=3000;i++){
        if(!k[i]){
            pri[++tot]=i,id[i]=tot-1,mx[i]=i;
            int now=i+i;
            while(now<=3000){
                k[now]=1,mx[now]=i;
                now+=i;
            }
        }
    }
    for(int i=0;i<(1<<16);i++){
        go[i]=1;
        for(int j=0;j<16;j++)if((1<<j)&i){
            go[i]=1ll*(pri[j+1]-1)*inv[pri[j+1]]%mod;
        }
    }
    for(int i=1;i<=n;i++)a[i].mx=mx[a[i].val];
    f[0][0]=1;
    std::sort(a+1,a+n+1);
    // for(int i=1;i<=n;i++)printf("%d ",a[i].mx);
    // puts("");
    for(int i=1;i<=n;i++){
        int o=i&1;
        memset(f[o],0,sizeof f[o]);
        int now=0;
        for(int j=1;j<=16;j++)if(a[i].val%pri[j]==0)now|=1<<(j-1);
        if(a[i].mx>53)now|=1<<16;
        if(a[i].mx!=a[i-1].mx){
            for(int j=0;j<(1<<16);j++)f[o^1][j]=ad(f[o^1][j],f[o^1][j|(1<<16)]);
        }
        for(int j=0;j<(1<<17);j++){
            int ooo=now^(j&now);
            int flag;
            if(ooo&(1<<16))flag=1,ooo^=(1<<16);
            else flag=0;
            ooo=go[ooo];
            if(flag)ooo=1ll*ooo*(a[i].mx-1)%mod*inv[a[i].mx]%mod;
            f[o][j|now]=ad(f[o][j|now],1ll*f[o^1][j]*a[i].val%mod*ooo%mod);
            f[o][j]=ad(f[o][j],f[o^1][j]);
        }
        // for(int j=0;j<(1<<3);j++){
        //     printf("%d %d\n",j,f[o][j]);
        // }
    }
    int ans=0;
    for(int j=0;j<(1<<17);j++)ans=ad(ans,f[n&1][j]);
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 2924kb

input:

5
1 6 8 6 2

output:

924

result:

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