QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750066 | #9619. 乘积,欧拉函数,求和 | Magiciannn | WA | 402ms | 4484kb | C++20 | 1.8kb | 2024-11-15 12:29:26 | 2024-11-15 12:29:26 |
Judging History
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);
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]) * val % mod;
g[z | tag] %= mod;
}
}
ll val = ((i == 1) ? 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] *= (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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 62ms
memory: 4188kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 62ms
memory: 4108kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 402ms
memory: 4452kb
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: 402ms
memory: 4484kb
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:
676371888
result:
wrong answer 1st lines differ - expected: '420709530', found: '676371888'