QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738695 | #9619. 乘积,欧拉函数,求和 | Arghariza | WA | 365ms | 4592kb | C++14 | 2.0kb | 2024-11-12 19:44:23 | 2024-11-12 19:44:46 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define R(i, x, y) for (int i = (x); i >= (y); i--)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
bool Mbe;
const int P = 998244353;
const int T = (1 << 16) + 5;
const int N = 2e3 + 5;
const int W = 3e3 + 5;
const int M = 20;
int n, S;
int a[N], f[2][T];
int pr[M] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
vector<pi> G[W];
int qpow(int p, int q) {
int res = 1;
for (; q; q >>= 1, p = 1ll * p * p % P)
if (q & 1) res = 1ll * res * p % P;
return res;
}
void solve() {
cin >> n, S = (1 << 16);
F (i, 1, n) {
cin >> a[i];
int s = 0, t = a[i];
F (j, 0, 15) {
if (t % pr[j] == 0) {
s |= (1 << j);
while (t % pr[j] == 0) {
t /= pr[j];
}
}
}
G[t].eb(s, a[i] / t);
}
f[0][0] = 1;
int o = 0;
F (i, 1, 3000) {
if (G[i].empty()) {
continue;
}
o ^= 1;
memcpy(f[o], f[o ^ 1], sizeof(f[o]));
int x = (i == 1) ? 1 : (1ll * (i - 1) * qpow(i, P - 2) % P);
for (pi p : G[i]) {
int t = p.fi, w = p.se;
R (s, S - 1, 0) {
(f[o][s | t] += 1ll * f[o][s] * w % P) %= P;
}
}
F (s, 0, S - 1) {
(f[o][s] += P - f[o ^ 1][s]) %= P;
f[o][s] = (1ll * f[o][s] * x % P + f[o ^ 1][s]) % P;
}
}
int res = 0;
F (s, 0, S - 1) {
if (!f[o][s]) {
continue;
}
int x = 1;
F (i, 0, 15) {
if ((s >> i) & 1) {
x = 1ll * x * (pr[i] - 1) % P * qpow(pr[i], P - 2) % P;
}
}
res += 1ll * f[o][s] * x % P;
res %= P;
}
cout << res << '\n';
}
bool Med;
int main() {
// FIO("");
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
int T = 1;
// cin >> T;
while (T--) solve();
cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4296kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4320kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 365ms
memory: 4592kb
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:
533898701
result:
wrong answer 1st lines differ - expected: '50965652', found: '533898701'