QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751106 | #9619. 乘积,欧拉函数,求和 | ucup-team3519# | RE | 90ms | 4144kb | C++17 | 3.1kb | 2024-11-15 17:07:05 | 2024-11-15 17:07:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
typedef long long LL;
const int mod = 998244353;
LL MOD(LL x) {
if(x >= mod) x -= mod;
if(x < 0) x += mod;
return x;
}
LL qpow(LL x, LL k) {
LL ans =1 ;
while(k) {
if(k & 1) {
ans = x * ans % mod;
}
k /= 2;
x = x * x % mod;
}
return ans;
}
const int N = 100;
const int T = 16;
bool is_pri[N];
int pri[N];
int inv[N];
void solve() {
for(int i = 1; i < N; i++) is_pri[i] = 1;
is_pri[1] = 0;
int cnt = 0;
for(int i = 2; i < N; i++) {
if(!is_pri[i]) continue;
pri[cnt++] = i;
for(int j = i * 2; j < N; j += i) {
is_pri[j] = 0;
}
}
for(int i = 1; i < N; i++) {
inv[i] = qpow(i, mod - 2);
}
struct info {
int c{1}, p{1}, bit;
};
int n; cin >> n;
V<info> a(n + 1);
for(int i = 1; i <= n; i++) {
int t; cin >> t;
for(int j = 0; j <= 15; j++) {
int p = pri[j];
if(t % p == 0) {
a[i].bit |= 1 << j;
}
while(t % p == 0) {
t /= p;
a[i].c *= p;
}
}
a[i].p = t;
}
sort(a.begin() + 1, a.end(), [&](info a, info b) {
return a.p < b.p;
});
V<LL> val(1 << 16);
for(int bit = 0; bit < 1 << 16; bit++) {
LL ans = 1;
for(int l = 1; l <= n; l++) {
int r = l;
while(r + 1 <= n && a[r + 1].p == a[l].p) r++;
LL cur = 1;
for(int i = l; i <= r; i++) {
if(a[i].bit & bit) continue;
cur *= (1 + a[i].c * a[i].p);
cur %= mod;
}
int p = a[l].p;
if(p != 1) {
cur = MOD((cur - 1) * (p - 1) % mod * inv[p] % mod + 1);
}
ans = cur * ans % mod;
// if(bit == 0) {
// cout << "l, r : " << l << " " << r << endl;
// cout << "p, cur : " << p << " " << cur << endl;
// }
l = r;
}
val[bit] = ans;
}
// cout << val[0] << " ";
// cout << endl;
V<LL> ans(1 << 16);
int all = (1 << 16) - 1;
for(int bit = 0; bit < 1 << T; bit++) {
int res = all ^ bit;
int now = res;
while(1) {
int time = 1;
if(__popcount(now) & 1) time = -1;
ans[bit] = MOD(ans[bit] + time * val[bit ^ now]);
if(now == 0) break;
now = (now - 1) & res;
}
}
LL tot_ans = 0;
for(int i = 0; i < 1 << T; i++) {
for(int j = 0; j < T; j++) {
if(!(i >> j & 1)) {
ans[i] = ans[i] * (pri[j] - 1) % mod * inv[pri[j]] % mod;
}
}
tot_ans = MOD(tot_ans + ans[i]);
}
cout << tot_ans << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
// int t; cin >> t;
// while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 90ms
memory: 4144kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 90ms
memory: 4108kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Runtime Error
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...