QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760588#9619. 乘积,欧拉函数,求和KeeperHihi#WA 0ms3620kbC++231.5kb2024-11-18 17:42:562024-11-18 17:42:58

Judging History

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

  • [2024-11-18 17:42:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2024-11-18 17:42:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;
const int MAX_A = 3000;

vector<int> compute_phi(int max_n) {
    vector<int> phi(max_n + 1);
    for (int i = 0; i <= max_n; i++) {
        phi[i] = i;
    }
    for (int i = 2; i <= max_n; i++) {
        if (phi[i] == i) { // i 是素数
            for (int j = i; j <= max_n; j += i) {
                phi[j] = phi[j] * (i - 1) / i;
            }
        }
    }
    return phi;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> freq(MAX_A + 1, 0);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        freq[a[i]]++;
    }

    vector<int> phi = compute_phi(MAX_A);

    vector<long long> dp(MAX_A + 1, 0);
    dp[1] = 1;

    for (int x = 1; x <= MAX_A; x++) {
        if (freq[x] > 0) {
            for (int j = MAX_A; j >= 1; j--) {
                if (dp[j] > 0) {
                    long long power = 1; // x^k
                    for (int k = 1; k <= freq[x]; k++) {
                        power = (power * x) % MOD;
                        if (j * power > MAX_A) break;
                        dp[j * power] = (dp[j * power] + dp[j]) % MOD;
                    }
                }
            }
        }
    }

    long long result = 0;
    for (int x = 1; x <= MAX_A; x++) {
        result = (result + dp[x] * phi[x] % MOD) % MOD;
    }

    cout << result << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

5
1 6 8 6 2

output:

784

result:

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