QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739901#9619. 乘积,欧拉函数,求和NightskyWA 118ms4828kbC++141.9kb2024-11-12 23:49:092024-11-12 23:49:10

Judging History

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

  • [2024-11-12 23:49:10]
  • 评测
  • 测评结果:WA
  • 用时:118ms
  • 内存:4828kb
  • [2024-11-12 23:49:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 3e3 + 5;
const int MOD = 998244353;
vector <int> prime;
int A[MAXN],n,sta[MAXN],id[MAXN];
ll f[2][(1<<16)+5];
bool isprime[MAXN];
ll qpw(ll x,ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b&1) ans = ans * x % MOD;
        x = x * x % MOD;
        b >>= 1;
    }
    return ans;
}
int main()
{
    int upperbound = sqrt(3000);
    for(int i = 2; i <= 3000; ++i)
    {
        if(isprime[i]) continue;
        if(i < upperbound)
        {
            id[i] = prime.size();
            prime.push_back(i);
        }
        for(int j = i + i; j <= 3000; j += i)
            isprime[j] = 1;
    }

    scanf("%d",&n);
    map <int,vector<int>> mp;
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d",&A[i]);
        int tmp = A[i];
        for(int p:prime)
        {
            if(A[i] % p == 0) sta[i] |= (1 << id[p]);
            while(tmp % p == 0) tmp /= p;
        }
        mp[tmp].push_back(i);
    }

    f[0][0] = 1;
    for(auto [p,vec] : mp)
    {
        for(int i : vec)
        {
            for(int s = (1<<16) - 1; s >= 0; --s)
            {
                int ts = s ^ sta[i];
                f[1][ts] = (f[1][ts] + f[0][s] * A[i] + f[1][s] * A[i]) % MOD;
            }
        }
        ll inv = qpw(p,MOD-2);
        for(int s = (1<<16) - 1; s >= 0; --s)
        {
            if(p != 1) f[1][s] = f[1][s] * inv % MOD * (p-1) % MOD;
            f[0][s] = (f[0][s] + f[1][s]) % MOD; 
        }
        memset(f[1],0,sizeof f[1]);
    }

    ll ans = 0;
    for(int s = 0; s < (1<<16); ++s)
    {
        for(int i = 0; i < 16; ++i)
        {
            ll inv = qpw(prime[i],MOD-2);
            if((1<<i) & s) f[0][s] = f[0][s] * inv % MOD * (prime[i]-1) % MOD;
        }
        ans = (ans + f[0][s]) % MOD;
    }
    printf("%lld\n",ans);
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 118ms
memory: 4828kb

input:

5
1 6 8 6 2

output:

103508

result:

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