QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738279#9619. 乘积,欧拉函数,求和wyhaoRE 65ms4224kbC++141.8kb2024-11-12 18:30:142024-11-12 18:30:16

Judging History

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

  • [2024-11-12 18:30:16]
  • 评测
  • 测评结果:RE
  • 用时:65ms
  • 内存:4224kb
  • [2024-11-12 18:30:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3005,M=66000,P=998244353;
int n;
int pri[N]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
struct node{
    int a;
    int b,ma;
}a[N];
bool cmp(node a,node b){
    return a.ma<b.ma;
}
int f[M],g[M];
int pw(int x,int k){
    int ans=1;
    for(;k;k>>=1,x=1ll*x*x%P){
        if(k&1) ans = 1ll*ans*x%P;
    }
    return ans;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i].a);
        a[i].ma=a[i].a;
        a[i].b=0;
        for(int j=0;j<16;j++){
            while(a[i].ma%pri[j]==0){
                a[i].ma/=pri[j];
                a[i].b|=(1<<j);
            }
        }
    }
    sort(a+1,a+n+1,cmp);
    f[0]=1;
    int l=n+1,r;
    for(int i=1;i<=n;i++){
        if(a[i].ma>1){
            l=i;
            break;   
        }
        for(int j=65535;j>=0;j--){
            f[j|a[i].b]=(f[j|a[i].b]+1ll*f[j]*a[i].a%P)%P;
        }
    }
    while(l<=n){
        r=l;
        while(r+1<=n and a[r+1].ma==a[l].ma) r++;
        memcpy(g,0,sizeof g);
        for(int i=l;i<=r;i++){
            for(int j=65535;j>=0;j--){
                g[j|a[i].b]=(g[j|a[i].b]+1ll*f[j]*a[i].a%P+1ll*g[j]*a[i].a%P)%P;
            }
        }
        int inv = 1ll*pw(a[l].ma,P-2)*(a[l].ma-1)%P;
        for(int j=65535;j>=0;j--){
            f[j]=(f[j]+1ll*g[j]*inv%P)%P;
        }
        l=r+1;
    }
    int ans=0;
    for(int j=0;j<65536;j++){
        int inv =1;
        for(int k=0;k<16;k++){
            if((j>>k)&1){
                inv =1ll*inv*(pri[k]-1)%P*pw(pri[k],P-2)%P;
            }
        }
        // if(f[j]) printf("%d %d %d\n",j,inv,f[j]);
        ans = (ans + 1ll*inv*f[j]%P)%P;
    }
    printf("%d",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 65ms
memory: 3968kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 65ms
memory: 4224kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Runtime Error

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:


result: