QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#837544#9619. 乘积,欧拉函数,求和jiangzhihuiWA 104ms266896kbC++141.9kb2024-12-30 06:43:342024-12-30 06:43:34

Judging History

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

  • [2024-12-30 06:43:34]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:266896kb
  • [2024-12-30 06:43:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int N=3005;
int primes[16],cnt;
bool check(int x){
    if(x<=1)return false;
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}
void init(){
    int idx=2;
    while(cnt<16){
        while(!check(idx))idx++;
        primes[cnt++]=idx;
        idx++;
    }
}
struct node{
    int v,s,tag;
    node(int v,int s,int tag):v(v),s(s),tag(tag){}
    node(){}
    bool operator < (const node& o)const{
        return tag<o.tag;
    }
};
int n,a[N];
node f[N];
int dp[1<<16][N];
int val[1<<16];
int ksm(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 calc(int p){
    if(p==1)return 1;
    return (1-ksm(p,mod-2)+mod)%mod;
}
int main(){
    init();
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        int x=a[i];
        int s=0;
        for(int j=0;j<16;j++){
            if(x%primes[j]==0){
                s|=1<<j;
                while(x%primes[j]==0)x/=primes[j];
            }
        }
        f[i]=node(a[i],s,calc(x));
    }
    sort(f+1,f+1+n);
    for(int j=0;j<(1<<16);j++){
        int res=1;
        for(int i=0;i<16;i++){
            if((j>>i)&1){
                res=1ll*res*calc(primes[i])%mod;
            }
        }
        val[j]=res;
    }
    dp[0][0]=1;
    for(int j=0;j<(1<<16);j++){
        for(int i=0;i<n;i++){
            dp[j][i+1]=(dp[j][i+1]+dp[j][i])%mod;
            int t=(j|f[i+1].s)^j;
            int res=1ll*dp[j][i]*val[t]%mod*f[i+1].v%mod*f[i+1].tag%mod;
            dp[j][i+1]=(dp[j][i+1]+res)%mod;
        }
    }
    int ans=0;
    for(int j=0;j<(1<<16);j++){
        ans=(ans+dp[j][n])%mod;
    }
    cout<<ans<<endl;
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 104ms
memory: 266896kb

input:

5
1 6 8 6 2

output:

180

result:

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