QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797110 | #9619. 乘积,欧拉函数,求和 | asxziill | WA | 1507ms | 4180kb | C++23 | 3.0kb | 2024-12-02 16:47:54 | 2024-12-02 16:47:59 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
constexpr int P = 998244353;
ll mul(ll a, ll b) {
return a * b % P;
}
ll add(ll a, ll b) {
ll res = a + b;
return (res >= P ? res - P : res);
}
ll neg(ll x) {
return (x == 0 ? x : P - x);
}
ll sub(ll a, ll b) {
return add(a, neg(b));
}
const int N = 16;
const int V = 3000;
const int S = 20;
const int v = 55;
int pw[v][S + 1];
std::vector<int> minp, primes;
std::vector<int> inv(v + 1), pi;
void sieve(int n) {
minp.assign(n + 1, 0);
primes.clear();
for (int i = 2; i <= n; i++) {
if (minp[i] == 0) {
minp[i] = i;
primes.push_back(i);
}
for (int p : primes) {
if (i * p > n) {
break;
}
minp[i * p] = p;
if (p == minp[i]) {
break;
}
}
}
for (int x : primes) {
if (x < v) {
inv[x] = pi.size();
pi.push_back(x);
pw[x][0] = 1;
for (int i = 0; i < S; i++) {
pw[x][i + 1] = mul(pw[x][i], x);
}
} else {
break;
}
}
}
void solve() {
int n;
std::cin >> n;
std::vector<int> a(n);
std::map<int, std::vector<int>> map;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
int mx = 0;
int x = a[i];
while (x > 1) {
mx = std::max(mx, minp[x]);
x /= minp[x];
}
if (mx < v) {
map[-1].push_back(a[i]);
} else {
map[mx].push_back(a[i] / mx);
}
}
int s = (1 << (N + 1));
int si = (1 << (N));
std::vector<int> f(s);
f[0] = 1;
for (auto &[p, arr] : map) {
for (int x : arr) {
// std::cout << p << " " << x << " p x \n";
auto g = f;
std::vector<int> cnt(pi.size());
while (x > 1) {
cnt[inv[minp[x]]]++;
x /= minp[x];
}
for (int sta = 0; sta < si; sta++) {
int t = sta;
int tmp = 1;
for (int i = 0; i < pi.size(); i++) {
if (cnt[i] > 0) {
t |= (1 << i);
if ((sta >> i) & 1) {
tmp = mul(tmp, pw[pi[i]][cnt[i]]);
} else {
tmp = mul(tmp, sub(pw[pi[i]][cnt[i]], pw[pi[i]][cnt[i] - 1]));
}
}
}
if (p == -1) {
g[t] = add(g[t], mul(tmp, f[sta]));
} else {
t |= (1 << N);
g[t] = add(g[t], mul(tmp, mul(f[sta], p - 1)));
g[t] = add(g[t], mul(tmp, mul(f[sta | (1 << N)], p)));
}
}
f = std::move(g);
}
for (int sta = 0; sta < si; sta++) {
f[sta] = add(f[sta], f[sta | (1 << N)]);
}
}
int ans = 0;
for (int sta = 0; sta < si; sta++) {
ans = add(ans, f[sta]);
}
std::cout << ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
sieve(V);
// sieve(v);
// std::cout << v;
// for (int i = 0; i < 5; i++) {
// std::cout << i << " " << pi[i] << " " << inv[pi[i]] << "\n";
// }
solve();
// std::cout << sub(pw[11][1], pw[11][0]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 4152kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 4180kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 1507ms
memory: 4112kb
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:
176655588
result:
wrong answer 1st lines differ - expected: '50965652', found: '176655588'