QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751250 | #9619. 乘积,欧拉函数,求和 | ucup-team2179# | WA | 436ms | 5424kb | C++20 | 2.0kb | 2024-11-15 17:43:54 | 2024-11-15 17:43:55 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define db double
#define pii pair<int, int>
#define ll long long
using namespace std;
const int N = 3333, maxn = (1 << 16) + 99, mod = 998244353;
int p[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int a[N], st[N], inv[N];
int f[maxn], n, g[2][maxn];
vector<int> v[N];
void solve() {
inv[1] = 1;
for (int i = 2; i <= 3000; i++)
inv[i] = mod - mod / i * inv[mod % i] % mod;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
int x = a[i];
for (int j = 0; j < 16; j++){
if(a[i] % p[j] == 0){
st[i] |= (1 << j);
while(a[i] % p[j] == 0)
a[i] /= p[j];
}
}
v[a[i]].push_back(i);
a[i] = x;
}
f[0] = 1;
for (int i = 1; i <= 3000; i++){
if(v[i].size() == 0)
continue;
int now = 0;
for(auto id : v[i]){
now ^= 1;
for(int j = 0; j < (1 << 16); j++)
g[now][j] = g[now ^ 1][j];
for (int j = 0; j < (1 << 16); j++){
g[now][j | st[id]] = (f[j] * a[id] + g[now][j | st[id]]) % mod;
g[now][j | st[id]] = (g[now][j | st[id]] + g[now ^ 1][j] * a[id]) % mod;
}
}
for (int j = 0; j < (1 << 16); j++){
if(i != 1)
f[j] = (f[j] + g[now][j] * inv[i] % mod * (i - 1)) % mod;
else
f[j] = (f[j] + g[now][j]) % mod;
g[0][j] = g[1][j] = 0;
}
}
int ans = 0;
for (int i = 0; i < (1 << 16); i++){
for (int j = 0; j < 16; j++)
if((i >> j) & 1){
f[i] = f[i] * inv[p[j]] % mod * (p[j] - 1);
}
ans = (ans + f[i]) % mod;
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 5240kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 5156kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 436ms
memory: 5424kb
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:
-898765943
result:
wrong answer 1st lines differ - expected: '50965652', found: '-898765943'