QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738656 | #9619. 乘积,欧拉函数,求和 | Zxyoul | WA | 143ms | 4244kb | C++23 | 2.3kb | 2024-11-12 19:39:02 | 2024-11-12 19:39:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pr(x) cerr << #x << "=" << (x) << endl
const int mod = 998244353;
const int N = 3e3 + 10;
int a[N];
int Big[N];
int state[N];
int primes[N], cnt;
bool st[N];
int A[N], inv[N], invA[N];
int p[1LL << 15];
void init() {
for(int i = 2; i <= (N - 10); i++) {
if(!st[i]) primes[cnt++] = i;
for (int j = 0; primes[j] <= (N - 10) / i; j++) {
st[primes[j] * i] = true;
if(i % primes[j] == 0) break;
}
}
for(int i = 1; i <= (N - 10); i++) {
for(int j = 0; j < cnt; j++) {
if(i % primes[j] == 0) {
if(j >= 15) {
Big[i] = primes[j];
}
else {
state[i] += (1LL << j);
}
}
}
}
p[0] = 1;
for(int i = 0; i < (1LL << 15); i++) {
p[i] = 1;
for(int j = 0; j < 15; j++) {
if(i >> j & 1) {
p[i] = 1LL * p[i] * inv[primes[j]] % mod;
p[i] = 1LL * p[i] * (primes[j] - 1) % mod;
}
}
}
}
int n;
int nxt[1LL << 15][2];
int dp[1LL << 15];
int U = 1LL << 15;
void sol(int x) {
for(int i = 0; i < U; i++) {
nxt[i][0] = dp[i];
nxt[i][1] = 0;
}
for(int i = 1; i <= n; i++) {
if(Big[a[i]] != x) continue;
int T = state[a[i]];
for(int S = 0; S < U; S++) {
nxt[T | S][1] = (nxt[T | S][1] + 1LL * nxt[T][0] * inv[x] % mod * (x - 1) % mod) % mod;
}
}
for(int i = 0; i < U; i++) {
dp[i] = (nxt[i][0] + nxt[i][1]) % mod;
}
}
void solve() {
cin >> n;
dp[0] = 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(!Big[a[i]]) {
int T = state[a[i]];
for(int S = (1LL << 15) - 1; S >= 0; S--) {
dp[T | S] = (dp[T | S] + 1LL * dp[S] * a[i] % mod) % mod;
}
}
}
for(int i = 15; i < cnt; i++) {
sol(primes[i]);
}
int ans = 0;
for(int i = 0; i < (1LL << 15); i++) {
ans = (ans + 1LL * dp[i] * p[i] % mod) % mod;
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t = 1; // cin >> t;
A[0] = inv[0] = invA[0] = 1;
A[1] = inv[1] = invA[1] = 1;
for(int i = 2; i < N; i++) {
A[i] = 1LL * A[i - 1] * i % mod;
inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
invA[i] = 1LL * invA[i - 1] * inv[i] % mod;
}
init();
while(t--) {
solve();
}
// system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 4244kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 25ms
memory: 4224kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 143ms
memory: 4220kb
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:
114014657
result:
wrong answer 1st lines differ - expected: '50965652', found: '114014657'