QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746455#9619. 乘积,欧拉函数,求和Qzong#WA 1112ms2984kbC++142.6kb2024-11-14 14:41:302024-11-14 14:41:32

Judging History

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

  • [2024-11-14 14:41:32]
  • 评测
  • 测评结果:WA
  • 用时:1112ms
  • 内存:2984kb
  • [2024-11-14 14:41:30]
  • 提交

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);
    // freopen("a.out","w",stdout);
    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=1;i<=10;i++)printf("%d ",pri[i]);
    // puts("");
    for(int i=0;i<(1<<16);i++){
        go[i]=1;
        // if(i<8)printf("%d\n",i);
        for(int j=0;j<16;j++)if((1<<j)&i){
            // if(i<8){
                // printf("%d ",j);
            // }
            go[i]=1ll*go[i]*(pri[j+1]-1)%mod*inv[pri[j+1]]%mod;
        }
        // if(i<8)puts("");
    }
    // printf("%d %d yes\n",go[5],go[4]);
    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].val);
    // 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(j<8)printf("%d %d %d %d %d=== =\n",j,now,j|now,1ll*f[o^1][j]*a[i].val%mod*ooo%mod,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]);
    // for(int j=0;j<(1<<16);j++)if(f[n&1][j|(1<<16)])puts("Wrong");
    printf("%d\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 2984kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 8ms
memory: 2952kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 1112ms
memory: 2956kb

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:

176655588

result:

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