QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736633 | #9619. 乘积,欧拉函数,求和 | cdd | WA | 418ms | 9012kb | C++20 | 4.7kb | 2024-11-12 12:08:18 | 2024-11-12 12:08:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
typedef pair<int, int> pii;
typedef long long LL;
typedef unsigned long long uLL;
const int inf32 = 1e9;
const LL inf64 = 1e18;
const int P = 998244353;
template<const int mod>
struct ModInt {
static const int P = mod;
int x;
ModInt (int x = 0) : x(x % P) {}
ModInt (LL x) : x(int(x % P)) {}
int val() {return x;}
ModInt operator + (const ModInt &a) const {int x0 = x + a.x; return ModInt(x0 < P ? x0 : x0 - P);}
ModInt operator - (const ModInt &a) const {int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + P : x0);}
ModInt operator * (const ModInt &a) const {return ModInt(1ll * x * a.x % P);}
ModInt operator / (const ModInt &a) const {return *this * a.inv();}
bool operator == (const ModInt &a) const {return x == a.x;};
bool operator != (const ModInt &a) const {return x != a.x;};
void operator += (const ModInt &a) {x += a.x; if (x >= P) x -= P;}
void operator -= (const ModInt &a) {x -= a.x; if (x < 0) x += P;}
void operator *= (const ModInt &a) {x = 1ll * x * a.x % P;}
void operator /= (const ModInt &a) {*this = *this / a;}
friend ModInt operator + (int y, const ModInt &a){int x0 = y + a.x; return ModInt(x0 < P ? x0 : x0 - P);}
friend ModInt operator - (int y, const ModInt &a){int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + P : x0);}
friend ModInt operator * (int y, const ModInt &a){return ModInt(1ll * a.x * y % P);}
friend ModInt operator / (int y, const ModInt &a){return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) {return os << (a.x + P) % P;}
friend istream &operator>>(istream &is, ModInt &t) {return is >> t.x;}
ModInt pow(LL n) const {
ModInt sum(1), base(x);
n %= (P - 1);
while (n) {
if (n & 1) sum *= base;
base *= base;
n >>= 1;
}
return sum;
}
ModInt inv() const {
int a = x, b = P, x = 1, y = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
x -= t * y; swap(x, y);
}
if (x < 0) y += P;
return x;
}
};
using mint = ModInt<P>;
const int maxn = 1e6 + 5;
int isprime[maxn], prime[maxn];
int prime_cnt = 0;
mint invprime[maxn];
void init(int n) {
for (int i = 2; i <= n; i++) {
if (!isprime[i]) {prime[++prime_cnt] = i;}
for (int j = 1; j <= prime_cnt; j++) {
if (prime[j] * i > n) break;
isprime[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
for (int i = 1; i <= 20; i++) invprime[i] = mint(prime[i]).inv();
}
struct node {
LL a, v, p;
};
int main()
{
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
init(3e3);
int T = 1;
while (T--) {
int n;
cin >> n;
vector<node> a(n + 5, {0, 0, 0});
for (int i = 1; i <= n; i++) cin >> a[i].a;
LL M = 16 + 1;
for (int i = 1; i <= n; i++) {
int x = a[i].a, v = 0;
for (int j = 1; j <= M - 1; j++) {
while (x % prime[j] == 0) {
x /= prime[j];
v |= (1 << (j - 1));
}
}
if (x >= 2) v |= 1 << (M - 1);
a[i].v = v;
a[i].p = x;
}
sort(a.begin() + 1, a.begin() + 1 + n, [&](node x, node y){
return x.p < y.p;
});
vector<mint> dp((1 << M) + 5, 0);
// auto lst = dp;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
// swap(dp, lst);
if (a[i].p != a[i - 1].p) {
// for (int j = (1 << (M - 1)); j < (1 << M); j++) lst[j ^ (1 << (M - 1))] += lst[j], dp[j] = lst[j] = 0;
for (int j = (1 << (M - 1)); j < (1 << M); j++) dp[j ^ (1 << (M - 1))] += dp[j], dp[j] = 0;
}
// dp = lst;
auto [x, v, p] = a[i];
prime[M] = p;
invprime[M] = mint(p).inv();
for (int j = (1 << M - 1); j >= 0; j--) {
mint tmp = dp[j];
if (tmp == 0) continue;
for (int k = 0; k < M; k++) {
if (!(j >> k & 1) && (v >> k & 1)) {
tmp *= mint(1) - mint(1) * invprime[k + 1];
}
}
dp[j | v] += tmp * x;
// cerr << j << " -> " << (j | v) << endl;
}
}
mint ans = 0;
for (int i = 0; i < (1 << M); i++) ans += dp[i];
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8940kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 2ms
memory: 8008kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 204ms
memory: 8408kb
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: 0
Accepted
time: 418ms
memory: 7908kb
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:
420709530
result:
ok single line: '420709530'
Test #5:
score: 0
Accepted
time: 3ms
memory: 8676kb
input:
30 37 14 35 33 38 42 46 3 26 7 16 1 35 38 48 3 43 49 18 3 29 1 43 43 20 6 39 20 14 38
output:
262613273
result:
ok single line: '262613273'
Test #6:
score: 0
Accepted
time: 3ms
memory: 8500kb
input:
30 39 31 49 2 4 28 30 12 13 34 7 28 17 37 38 18 41 33 29 36 18 7 3 14 30 42 35 14 18 35
output:
234142118
result:
ok single line: '234142118'
Test #7:
score: -100
Wrong Answer
time: 181ms
memory: 9012kb
input:
200 53 37 234 248 66 30 64 181 38 130 250 27 199 226 43 185 207 241 38 296 68 18 145 20 64 127 57 30 168 267 221 116 115 192 17 26 5 63 3 127 52 48 229 58 69 111 20 244 234 35 48 217 179 189 89 60 285 106 43 104 36 28 62 281 104 38 281 264 140 275 105 20 203 271 222 262 123 10 82 263 118 254 229 222...
output:
603975572
result:
wrong answer 1st lines differ - expected: '617035263', found: '603975572'