QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760588 | #9619. 乘积,欧拉函数,求和 | KeeperHihi# | WA | 0ms | 3620kb | C++23 | 1.5kb | 2024-11-18 17:42:56 | 2024-11-18 17:42:58 |
Judging History
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;
}
詳細信息
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'