QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740920#9619. 乘积,欧拉函数,求和qzhfxWA 33ms3556kbC++232.0kb2024-11-13 12:21:122024-11-13 12:21:12

Judging History

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

  • [2024-11-13 12:21:12]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:3556kb
  • [2024-11-13 12:21:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll inv(ll x)
{
    return qpow(x, mod - 2);
}
int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
using pii = pair<int, int>;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    map<int, vector<pii>> mp;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        int tmp = a[i];
        int mask = 0;
        for (int j = 0; j < 15; j++)
        {
            while (a[i] % pr[j] == 0)
            {
                a[i] /= pr[j];
                mask |= (1 << j);
            }
        }
        if (a[i] == 53 * 53)
            a[i] = 53;
        mp[a[i]].push_back({mask, tmp});
    }
    vector<ll> dp(1 << 15), ndp(1 << 15);
    for (auto [p, v] : mp)
    {
        // ndp = dp;
        // cerr << p << '\n';
        dp.assign(1 << 15, 0);
        dp[0] = 1;
        for (auto [mask, x] : v)
        {
            for (int j = (1 << 15) - 1; j >= 0; j--)
            {
                dp[j | mask] = (dp[j | mask] + dp[j] * x % mod) % mod;
            }
        }
        for (int j = 0; j < (1 << 15); j++)
        {
            ndp[j] += (dp[j] * max(1ll, inv(p)) * (p - 1) % mod + mod) % mod;
            ndp[j] %= mod;
        }
    }
    ll ans = 0;
    for (int i = 0; i < (1 << 15); i++)
    {
        for (int j = 0; j < 15; j++)
        {
            if (i >> j & 1)
            {
                ndp[i] = ndp[i] * (pr[j] - 1) % mod * inv(pr[j]) % mod;
            }
        }
        ans += ndp[i];
        ans %= mod;
    }
    cout << ans << '\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    // cin >> _;
    while (_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 33ms
memory: 3556kb

input:

5
1 6 8 6 2

output:

0

result:

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