QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752280 | #9619. 乘积,欧拉函数,求和 | lilab | WA | 1613ms | 3896kb | C++20 | 3.2kb | 2024-11-15 23:50:01 | 2024-11-15 23:50:02 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define tp ll
#define ptp pair<tp,tp>
#define pdb pair<db,db>
#define umap unordered_map
#define P 998244353ll
#define ed '\n'
using namespace std;
tp n, m;
struct shuzi {
tp x;
tp mapri;
};
vector<shuzi>a;
vector<tp>pri;
umap<tp, tp>prid;
vector<tp>dp;
void prime_init(tp n, vector<tp>& prime) {
vector<tp>not_prime(n + 5);
for (int i = 2; i <= n; ++i) {
if (!not_prime[i]) {
prime.push_back(i);
}
for (int pri_j : prime) {
if (i * pri_j > n) break;
not_prime[i * pri_j] = true;
if (i % pri_j == 0) {
break;
}
}
}
}
tp ksm(tp a, tp b) {
tp lsans = 1;
while (b) {
if (b & 1ll) {
lsans = (lsans * a) % P;
}
a = (a * a) % P;
b >>= 1;
}
return lsans;
}
void init() {
prime_init(3000, pri);
tp tot = 0;
for (auto& it : pri) {
if (it <= 50) {
prid[it] = tot;
++tot;
}
else {
prid[it] = tot;
}
}
}
void clear() {
a = vector<shuzi>(n + 5);
dp = vector<tp>((1ll << 16));
}
void solve() {
cin >> n;
clear();
for (tp i = 1; i <= n; i++) {
cin >> a[i].x;
for (auto& it : pri) {
if (it <= 50) {
continue;
}
if (a[i].x % it == 0) {
a[i].mapri = it;
}
}
}
sort(a.begin() + 1, a.begin() + n + 1, [](const shuzi& x, const shuzi& y) {
return x.mapri < y.mapri;
});
dp[0] = 1;
for (tp i = 1; i <= n; i++) {
if (a[i].mapri != a[i - 1].mapri) {
if (a[i - 1].mapri != 0) {
tp tmp = a[i - 1].mapri;
for (tp j = (1ll << 15); j < (1ll << 16); j++) {
dp[j ^ (1ll << 15)] = (dp[j ^ (1ll << 15)] + dp[j] * (1 - ksm(tmp, P - 2) + P)) % P;//乘上1-1/tmp
dp[j] = 0;
}
}
}
tp ad = 0;
for (auto& it : pri) {
if (a[i].x < it) {
break;
}
if (a[i].x % it == 0) {
ad += (1ll << prid[it]);
}
}
for (tp j = (1ll << 16) - 1; j >= 0; j--) {
dp[j | ad] = (dp[j | ad] + dp[j] * a[i].x) % P;
}
}
if (a[n].mapri != 0) {
tp tmp = a[n].mapri;
for (tp j = (1ll << 15); j < (1ll << 16); j++) {
dp[j ^ (1ll << 15)] = (dp[j ^ (1ll << 15)] + dp[j] * (1 - ksm(tmp, P - 2) + P)) % P;//乘上1-1/tmp
dp[j] = 0;
}
}
tp ans = 0;
for (tp i = 0; i < (1ll << 15); i++) {
tp cnt = dp[i];
for (tp j = 0; j < 15; j++) {
if (i & (1ll << j)) {
cnt = (cnt * (1 - ksm(pri[j], P - 2) + P)) % P;
}
}
ans += cnt;
}
cout << ans << ed;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
init();
int _t = 1;
//cin >> _t;
while (_t--) {
solve();
}
}
/*
3
1 2 3
*/
详细
Test #1:
score: 100
Accepted
time: 25ms
memory: 3588kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 25ms
memory: 3896kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 1613ms
memory: 3868kb
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:
2038465934478
result:
wrong answer 1st lines differ - expected: '50965652', found: '2038465934478'