QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#777033 | #9619. 乘积,欧拉函数,求和 | ewe | WA | 1224ms | 6016kb | C++14 | 3.1kb | 2024-11-23 22:22:45 | 2024-11-23 22:22:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fopen \
freopen("E:/vscode/oi/in.txt", "r", stdin); \
freopen("E:/vscode/oi/out.txt", "w", stdout);
#define ios \
ios::sync_with_stdio(0); \
cin.tie(0);
#define i64 long long
#define ull unsigned i64
#define pii pair<int, int>
#define pdd pair<double, double>
#define ld long double
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) (x & -x)
#define de(x) cout << #x << " = " << x << '\n'
#define MAXP 20
const int N = 2e3 + 10, M = 3e3 + 10, mod = 998244353;
const double eps = 1e-12;
const double PI = acos(-1);
bool Mst;
#define int i64
const int pri[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
vector<array<int, 2>> vec[M];
int qsm(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int calc(int p)
{
return (p - 1) * qsm(p, mod - 2) % mod;
}
void solve()
{
int n;
cin >> n;
for (int id = 0; id < n; id++)
{
int x;
cin >> x;
int mask = 0, val = x;
for (int i = 0; i < 16; i++)
{
int p = pri[i];
if (x % p == 0)
{
while (x % p == 0)
x /= p;
mask |= 1 << i;
}
}
vec[x].push_back({mask, val});
}
vector<int> dp(1 << 17, 0);
vector<int> f(1 << 16), g(16);
for (int i = 0; i < 16; i++)
g[i] = calc(pri[i]);
for (int x = 0; x < (1 << 16); x++)
{
f[x] = 1;
for (int i = 0; i < 16; i++)
if (x >> i & 1)
f[x] = f[x] * g[i] % mod;
}
dp[0] = 1;
for (int p = 1; p < M; p++)
{
if (vec[p].empty())
continue;
int maxp = calc(p);
bool isfir = true;
for (auto [mask, val] : vec[p])
{
auto ndp = dp;
if (p > 1)
mask |= 1 << 16;
for (int i = 0; i < (1 << 17); i++)
{
int j = i | mask, k = j ^ i;
int res = dp[i] * val % mod;
if (isfir && p > 1)
k |= 1 << 16;
if (k >> 16 & 1)
{
res = res * maxp % mod;
k ^= 1 << 16;
}
assert(k < (1 << 16));
res = res * f[k] % mod;
ndp[j] = (ndp[j] + res) % mod;
}
dp = ndp;
isfir = false;
}
}
int ans = 0;
for (auto x : dp)
ans = (ans + x) % mod;
cout << ans << '\n';
}
bool Med;
signed main()
{
ios;
// fopen;
cerr << (&Med - &Mst) / 1024 / 1024;
int t = 1;
srand(time(0));
cout << fixed << setprecision(12);
// cin >> t;
for (int i = 1; i <= t; i++)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 9ms
memory: 5924kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 10ms
memory: 5820kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 1224ms
memory: 6016kb
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: 1213ms
memory: 5796kb
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: 23ms
memory: 5820kb
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: 23ms
memory: 5832kb
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: 125ms
memory: 5780kb
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:
195917877
result:
wrong answer 1st lines differ - expected: '617035263', found: '195917877'