QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747830 | #9619. 乘积,欧拉函数,求和 | Green_Hand | WA | 66ms | 6368kb | C++20 | 2.2kb | 2024-11-14 18:24:34 | 2024-11-14 18:24:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3E3 + 7, M = 1 << 15, P = 998244353;
int n,m,ans,tot,mx[N],tag[N],val[N],prime[N],a[N],f[N][2][M];
int cmp(int x,int y) { return mx[x] > mx[y]; }
void pls(int &x,int y) { x = (x + y) % P; }
int pow(int a,int p)
{
int rest = 1;
for(;p;p >>= 1, a = 1ll * a * a % P)
if(p & 1) rest = 1ll * rest * a % P;
return rest;
}
void read(int &x)
{
char c = getchar(); x = 0;
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}
void prepare()
{
mx[1] = 1;
for(int i = 2;i < N; ++ i)
{
if(!tag[i]) prime[++tot] = mx[i] = i;
val[i] = 1ll * (i - 1) * pow(i,P - 2) % P;
for(int j = 1;j <= tot; ++ j)
{
if(i * prime[j] >= N) break;
tag[i * prime[j]] = 1, mx[i * prime[j]] = mx[i];
if(!(i % prime[j])) break;
}
}
}
int main()
{
read(n), prepare();
for(int i = 1;i <= n; ++ i) read(a[i]);
sort(a + 1,a + n + 1,cmp), m = f[0][0][0] = 1;
while(n && a[n] == 1) pls(m,m), -- n;
for(int i = 1,u = 0,v = 1,S;i <= n; ++ i)
{
S = 0;
for(int j = 1;j <= 15; ++ j)
if(!(a[i] % prime[j])) S |= 1 << j - 1;
if(mx[a[i]] < 53)
{
for(int j = 0;j < M; ++ j)
f[v][0][j] = f[u][0][j] = (f[u][0][j] + f[u][1][j]) % P,
f[u][1][j] = f[v][1][j] = 0;
for(int j = 0;j < M; ++ j)
pls(f[v][0][j | S],1ll * f[u][0][j] * a[i] % P);
}
else if(i > 1 && mx[a[i]] == mx[a[i - 1]])
{
for(int j = 0;j < M; ++ j)
f[v][0][j] = f[u][0][j], f[v][1][j] = f[u][1][j];
for(int j = 0;j < M; ++ j)
pls(f[v][1][j | S],1ll * (f[u][0][j] + f[u][1][j]) * a[i] % P * val[mx[a[i]]] % P);
}
else
{
for(int j = 0;j < M; ++ j)
f[v][0][j] = f[u][0][j] = (f[u][0][j] + f[u][1][j]) % P,
f[u][1][j] = f[v][1][j] = 0;
for(int j = 0;j < M; ++ j)
pls(f[v][1][j | S],1ll * f[u][0][j] * a[i] % P * val[mx[a[i]]] % P);
}
u ^= 1, v ^= 1;
}
ans = 0;
for(int j = 0,x;j < M; ++ j)
{
x = 1;
for(int k = 1;k <= 15; ++ k)
if(j & (1 << k - 1)) x = 1ll * x * val[prime[k]] % P;
pls(ans,1ll * (f[n & 1][0][j] + f[n & 1][1][j]) * x % P);
}
pls(ans,P), printf("%d\n",1ll * ans * m % P);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 4340kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 3ms
memory: 4336kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 66ms
memory: 5976kb
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: 61ms
memory: 4508kb
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: 7ms
memory: 6368kb
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: 4272kb
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: 29ms
memory: 4500kb
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:
783622698
result:
wrong answer 1st lines differ - expected: '617035263', found: '783622698'