QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#797245 | #9619. 乘积,欧拉函数,求和 | Hojstyer | WA | 304ms | 3944kb | C++20 | 2.8kb | 2024-12-02 19:49:38 | 2024-12-02 19:49:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3001;
int prime[MAXN], flag[MAXN], d[MAXN], tot, mp[MAXN], inv[MAXN];
vector<int> p[MAXN];
int m;
const int mod = 998244353;
ll qpow(ll a, ll b)
{
ll res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void init()
{
int n = 3000;
d[1] = 1;
for (int i = 2; i <= n; ++i)
{
if (!flag[i])
{
prime[++tot] = i;
mp[i] = tot;
d[i] = i;
}
for (int j = 1; j <= tot && prime[j] * i <= n; ++j)
{
flag[prime[j] * i] = 1;
d[prime[j] * i] = prime[j];
if (i % prime[j] == 0)
break;
}
}
for (int i = 1; i <= n; ++i)
inv[i] = qpow(i, mod - 2);
for (int i = 1; i <= tot; ++i)
if (prime[i] <= 53)
++m;
}
void solve()
{
int n;
cin >> n;
int S = 1 << m;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
int x = a[i], pg = 1;
while (x != 1)
{
if (d[x] > prime[m - 1])
pg = max(pg, d[x]);
x /= d[x];
}
p[pg].push_back(a[i] / pg);
}
// O(n * 2 ^ m)
int ans = 0;
int k = 3000;
vector<int> dp(S << 1);
dp[0] = 1;
for (int u = 1; u <= k; ++u)
{
if (p[u].empty())
continue;
for (int x : p[u])
{
int j = 0, y = x;
while (y != 1)
{
j |= 1 << (mp[d[y]] - 1);
y /= d[y];
}
if (u != 1)
for (int i = S * 2 - 1; i >= 0; --i)
{
if (i >> m & 1)
dp[i | j] = (dp[i | j] + 1ll * dp[i] * x * (u - 1) % mod) % mod;
else
dp[i | j | 1 << m] = (dp[i | j | 1 << m] + 1ll * dp[i] * x * u % mod) % mod;
}
else
for (int i = S - 1; i >= 0; --i)
dp[i | j] = (dp[i | j] + 1ll * dp[i] * x) % mod;
}
for (int i = 0; i < S; ++i)
dp[i] = (dp[i] + dp[i | 1 << m]) % mod, dp[i | 1 << m] = 0;
}
for (int i = 0; i < S; ++i)
{
dp[i] = dp[i];
for (int j = 0; j < m; ++j)
if (i >> j & 1)
dp[i] = 1ll * dp[i] * inv[prime[j + 1]] % mod * (prime[j + 1] - 1) % mod;
ans = (ans + dp[i]) % mod;
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
init();
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 3944kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3832kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 304ms
memory: 3824kb
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:
480383856
result:
wrong answer 1st lines differ - expected: '50965652', found: '480383856'