QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#758322 | #9619. 乘积,欧拉函数,求和 | electricstick# | WA | 312ms | 2692kb | C++20 | 2.1kb | 2024-11-17 17:44:30 | 2024-11-17 17:44:32 |
Judging History
answer
#include<cstdio>
#include<algorithm>
const int N = 3010, mod = 998244353, Sq = 55, M = 16;
int n, a[N];
int p[M] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int f[2][(1 << M) + 10][2];
int inv[N];
struct num {
int stu;
int bigp;
int data;
bool operator< (const num &oth) {
return bigp < oth.bigp;
}
}c[N];
int main() {
inv[1] = 1;
for(int i = 2; i <= 3000; i++) {
inv[i] = mod - 1ll * inv[mod % i] * (mod / i) % mod;
}
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
c[i].data = a[i];
int x = a[i], y = 0;
for(int j = 0; j < 16; j++) {
if(x % p[j] == 0) {
y |= (1 << j);
while(x % p[j] == 0) x /= p[j];
}
}
c[i].bigp = x;
c[i].stu = y;
}
std::sort(c + 1, c + 1 + n);
f[0][0][0] = 1;
for(int i = 1; i <= n; i++) {
if(c[i].bigp != c[i - 1].bigp) {
for(int j = 0; j < (1 << 16); j++) {
f[i&1^1][j][0] = (f[i&1^1][j][0]+1ll*f[i&1^1][j][1]*(c[i-1].bigp==1?1:inv[c[i-1].bigp]%mod*(c[i-1].bigp-1)))%mod;
f[i&1^1][j][1] = 0;
}
}
for(int j = 0; j < (1 << 16); j++) {
f[i&1][j][0] = f[i&1^1][j][0];
f[i&1][j][1] = f[i&1^1][j][1];
}
for(int j = 0; j < (1 << 16); j++) {
f[i&1][j|c[i].stu][1] = (f[i&1][j|c[i].stu][1] + 1ll*(f[i&1^1][j][0]+f[i&1^1][j][1])*c[i].data)%mod;
}
// printf("##%d: %d %d\n", i, c[i].stu, c[i].data);
// for(int j = 0; j < (1 << 3); j++) {
// printf("%d %d\n", j, f[i&1][j][1]);
// }
}
int ans = 0;
for(int j = 0; j < (1 << 16); j++) {
int now = (f[n&1][j][0] + 1ll*f[n&1][j][1]*(c[n].bigp==1?1:inv[c[n].bigp]%mod*(c[n].bigp-1)))%mod;
// printf("%d %d\n", j, now);
for(int k = 0; k < 16; k++) {
if((j >> k) & 1) {
now = 1ll * now * inv[p[k]] % mod * (p[k] - 1) % mod;
}
}
ans = (ans + now) % mod;
}
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 2636kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 2692kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 312ms
memory: 2600kb
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:
-30518812
result:
wrong answer 1st lines differ - expected: '50965652', found: '-30518812'