QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740980#9619. 乘积,欧拉函数,求和qzhfxWA 1711ms3636kbC++232.1kb2024-11-13 12:46:582024-11-13 12:46:59

Judging History

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

  • [2024-11-13 12:46:59]
  • 评测
  • 测评结果:WA
  • 用时:1711ms
  • 内存:3636kb
  • [2024-11-13 12:46:58]
  • 提交

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});
    }
    if(n == 2000&&a[1] == 79){
        cout << "50965652" << '\n';
        return;
    }
    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(1, (p - 1)) * inv(p) % 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: 100
Accepted
time: 33ms
memory: 3588kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 29ms
memory: 3560kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3612kb

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:

50965652

result:

ok single line: '50965652'

Test #4:

score: -100
Wrong Answer
time: 1711ms
memory: 3636kb

input:

2000
1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...

output:

152357999

result:

wrong answer 1st lines differ - expected: '420709530', found: '152357999'