QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#737194 | #9619. 乘积,欧拉函数,求和 | Andeviking | WA | 560ms | 5396kb | C++20 | 2.5kb | 2024-11-12 15:00:24 | 2024-11-12 15:00:26 |
Judging History
answer
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t int128;
typedef pair<int, int> pii;
#define iofast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define lowbit(x) (x & (-x))
#define inv(x) qpow(x, mod - 2)
#define debug(x) cout << (#x) << " = " << x << endl
#define range(x) (x).begin(), (x).end()
const int iINF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
/*---------------------------------------*/
const int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
const int N = 2005;
const int limit = (1 << 16);
ll dp[limit];
const ll mod = 998244353;
ll qpow(ll a, ll b)
{
ll ans = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
}
return ans % mod;
}
void solve()
{
int n;
cin >> n;
vector<int> a(n + 5);
map<int, vector<pii>> mp;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
int x = a[i];
int mask = 0;
for (int j = 0; j < 16; ++j) {
int y = primes[j];
while (x % y == 0) {
x /= y;
mask |= (1 << j);
}
}
mp[x].emplace_back(mask, a[i] / x);
}
dp[0] = 0;
for (const auto &[p, v] : mp) {
ll use[limit] = {1};
for (const auto &[mask, val] : v) {
ll temp[limit] = {0};
for (int j = 0; j < limit; ++j)
(temp[j | mask] += use[j] * p % mod * val) %= mod;
for (int j = 0; j < limit; ++j)
(use[j] += temp[j]) %= mod;
}
if (p > 1) {
ll inv = qpow(p, mod - 2);
for (int j = 0; j < limit; ++j) {
(use[j] *= (p - 1)) %= mod;
(use[j] *= inv) %= mod;
}
}
for (int j = 0; j < limit; ++j)
(dp[j] += use[j]) %= mod;
}
ll ans = 0;
for (int j = 0; j < limit; ++j) {
for (int i = 0; i < 16; ++i) {
if (j & (1 << i)) {
ll inv = qpow(primes[i], mod - 2);
(dp[j] *= (primes[i] - 1)) %= mod;
(dp[j] *= inv) %= mod;
}
}
(ans += dp[j]) %= mod;
}
cout << ans << '\n';
}
/*---------------------------------------*/
int main()
{
iofast;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 61ms
memory: 5396kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 65ms
memory: 5396kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 560ms
memory: 5108kb
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:
228979119
result:
wrong answer 1st lines differ - expected: '50965652', found: '228979119'