QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749135#9619. 乘积,欧拉函数,求和ty09WA 275ms4376kbC++171.6kb2024-11-14 22:47:462024-11-14 22:47:46

Judging History

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

  • [2024-11-14 22:47:46]
  • 评测
  • 测评结果:WA
  • 用时:275ms
  • 内存:4376kb
  • [2024-11-14 22:47:46]
  • 提交

answer

#include"bits/stdc++.h"
#define endl '\n'
using ll=long long;
using namespace std;
constexpr int N=1e5+10,inf=0X3F3F3F3F,mod=998244353;
constexpr ll INF=0X3F3F3F3F3F3F3F3F;
ll qpow(ll a,ll b,ll p=mod){
    ll r=1;
    for(;b;b>>=1){
        if(b&1)
            r=r*a%p;
        a=a*a%p;
    }
    return r;
}
ll inv(ll a,ll p=mod){
    return qpow(a,mod-2);
}
int pr[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
void solve(){
    int n;
    cin>>n;
    vector<int>a(n);
    vector<vector<array<int,2>>>p(3001);
    for(int i=0;i<n;i++){
        cin>>a[i];
        int w=a[i];
        int mask=0;
        for(int j=0;j<16;j++){
            if(w<pr[j])
                break;
            if(w%pr[j]==0)
                mask|=1<<j;
            while(w%pr[j]==0)
                w/=pr[j];
        }
        p[w].push_back({a[i],mask});
    }
    
    vector<ll>f(1<<16),g(1<<16);
    f[0]=1;
    for(int i=1;i<=3000;i++){
        if(p[i].empty())
            continue;
        fill(g.begin(),g.end(),0);
        for(auto [val,mask]:p[i]){
            for(int s=(1<<16)-1;s>=0;s--){
                (g[s|mask]+=(f[s]+g[s])*val)%=mod;
            }
        }
        ll val=1?i==1:(i-1)*inv(i);
        for(int s=0;s<(1<<16);s++){
            (f[s]+=g[s]*val)%=mod;
        }
    }

    ll ans=0;
    for(int s=0;s<(1<<16);s++){
        for(int i=0;i<16;i++){
            if(s>>i&1)
                (f[s]*=(pr[i]-1)*inv(pr[i]))%=mod;
        }
        (ans+=f[s])%=mod;
    }
    cout<<ans<<endl;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
//	int t;cin>>t;while(t--)
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 58ms
memory: 4108kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 61ms
memory: 4184kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 275ms
memory: 4376kb

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:

-718268851

result:

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