QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750086#9619. 乘积,欧拉函数,求和MagiciannnCompile Error//C++201.9kb2024-11-15 12:34:342024-11-15 12:34:35

Judging History

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

  • [2024-11-15 12:34:35]
  • 评测
  • [2024-11-15 12:34:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using LL = long long;

const int N = 3005;
const int M = 16;
const int mod = 998244353;

int pri[M] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 42, 47, 53};

ll binPow(ll a, ll k = mod - 2) {
    ll res = 1;
    while (k) {
        if (k & 1) res = res * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return res;
}

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    vector<vector<array<int, 2>>> p(N);
    for (int i = 0;i < n;i++) {
        cin >> a[i];
        int P = a[i];
        int tag = 0;
        for (int j = 0;j < M;j++) {
            if (P % pri[j] == 0) {
                tag |= (1 << j);
            }
            while (P % pri[j] == 0) P /= pri[j];
        }
        p[P].push_back({a[i], tag});
    }

    vector<ll> f(1 << M, 0LL);
    f[0] = 1;
    for (int i = 1;i <= N - 5;i++) {
        if (p[i].empty()) continue;
        vector<ll> g(1 << M, 0LL);
        for (auto [val, tag] : p[i]) {
            for (int z = (1 << M) - 1;z >= 0;z--) {
                g[z | tag] += ((f[z] + g[z]) % mod) * val % mod;
                g[z | tag] %= mod;
            }
        }
        if (i == 1) val = 1LL;
        else val = 1LL * (i - 1) * binPow(i) % mod;
        for (int z = 0;z < (1 << M);z++) {
            f[z] += g[z] * val % mod;
            f[z] %= mod;
        }
    }

    ll res = 0;
    for (int z = 0;z < (1 << M);z++) {
        for (int i = 0;i < M;i++) {
            if ((z >> i) & 1) {
                f[z] %= mod;
                f[z] *= 1LL * (pri[i] - 1) * binPow(pri[i]) % mod;
                f[z] %= mod;
            }
        }
        res = (res + f[z]) % mod;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:50:21: error: ‘val’ was not declared in this scope
   50 |         if (i == 1) val = 1LL;
      |                     ^~~
answer.code:51:14: error: ‘val’ was not declared in this scope
   51 |         else val = 1LL * (i - 1) * binPow(i) % mod;
      |              ^~~
answer.code:53:28: error: ‘val’ was not declared in this scope
   53 |             f[z] += g[z] * val % mod;
      |                            ^~~