QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738897#9619. 乘积,欧拉函数,求和qstbcdTL 846ms4864kbC++232.2kb2024-11-12 20:11:302024-11-12 20:11:45

Judging History

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

  • [2024-11-12 20:11:45]
  • 评测
  • 测评结果:TL
  • 用时:846ms
  • 内存:4864kb
  • [2024-11-12 20:11:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int mod = 998244353;
int __t = 1, n;
int prime[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 1};
void solve() {
    map<int, vector<pair<int, int>>> mp;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        int nd = 0, sum = 1;
        for (int i = 0; i < 16; i++) {
            while (x % prime[i] == 0) {
                x /= prime[i];
                if ((nd & (1 << i)) == 1)
                    sum = (sum * prime[i]) % mod;
                nd |= (1 << i);
            }
        }
        mp[x].push_back({nd, sum});
    }
    map<int, int, greater<int>> dp;
    dp[0] = 1;
    for (auto [x, vec] : mp) {
        prime[16] = x;
        for (auto [nd, sum] : vec) {
            if (x != 1)
                nd |= 1 << 16;
            for (auto [i, dpi] : dp) {
                int nsum = sum, nnd = nd | i;
                for (int j = 0; j < 17; j++) {
                    if ((i & (1 << j)) == 0 && (nd & (1 << j)) != 0) {
                        nsum = (nsum * max(prime[j] - 1, 1ll)) % mod;
                    }
                    if ((i & (1 << j)) != 0 && (nd & (1 << j)) != 0) {
                        nsum = (nsum * prime[j]) % mod;
                    }
                }
                dp[nnd] = (dp[nnd] + dpi * nsum % mod) % mod;
            }
        }
        // cout << "x = " << x << '\n';
        // for (auto [i, dpi] : dp) {
        //     cout << i << ' ' << dpi << '\n';
        // }
        vector<int> del;
        for (auto [i, dpi] : dp) {
            if ((i & (1 << 16)) != 0) {
                dp[i ^ (1 << 16)] = (dp[i ^ (1 << 16)] + dpi) % mod;
                del.push_back(i);
            }
        }
        for (auto i : del) {
            dp.erase(i);
        }
    }
    int sum = 0;
    for (auto [i, dpi] : dp) {
        sum = (sum + dpi) % mod;
    }
    cout << sum << '\n';
    return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    // cin >> __t;
    while (__t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: 0
Accepted
time: 846ms
memory: 4864kb

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
Time Limit Exceeded

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:


result: