QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740924 | #9619. 乘积,欧拉函数,求和 | qzhfx | WA | 1709ms | 3648kb | C++23 | 2.0kb | 2024-11-13 12:22:00 | 2024-11-13 12:22:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 7;
const int mod = 998244353;
ll qpow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll inv(ll x)
{
return qpow(x, mod - 2);
}
int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
using pii = pair<int, int>;
void solve()
{
int n;
cin >> n;
vector<int> a(n + 1);
map<int, vector<pii>> mp;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
int tmp = a[i];
int mask = 0;
for (int j = 0; j < 15; j++)
{
while (a[i] % pr[j] == 0)
{
a[i] /= pr[j];
mask |= (1 << j);
}
}
if (a[i] == 53 * 53)
a[i] = 53;
mp[a[i]].push_back({mask, tmp});
}
vector<ll> dp(1 << 15), ndp(1 << 15);
for (auto [p, v] : mp)
{
// ndp = dp;
// cerr << p << '\n';
dp.assign(1 << 15, 0);
dp[0] = 1;
for (auto [mask, x] : v)
{
for (int j = (1 << 15) - 1; j >= 0; j--)
{
dp[j | mask] = (dp[j | mask] + dp[j] * x % mod) % mod;
}
}
for (int j = 0; j < (1 << 15); j++)
{
ndp[j] += (dp[j] * max(1, (p - 1)) * inv(p) % mod + mod) % mod;
ndp[j] %= mod;
}
}
ll ans = 0;
for (int i = 0; i < (1 << 15); i++)
{
for (int j = 0; j < 15; j++)
{
if (i >> j & 1)
{
ndp[i] = ndp[i] * (pr[j] - 1) % mod * inv(pr[j]) % mod;
}
}
ans += ndp[i];
ans %= mod;
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 33ms
memory: 3580kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 33ms
memory: 3540kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 1709ms
memory: 3648kb
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:
989782900
result:
wrong answer 1st lines differ - expected: '50965652', found: '989782900'