QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759209 | #9619. 乘积,欧拉函数,求和 | woodie_0064# | WA | 1ms | 3572kb | C++20 | 2.5kb | 2024-11-17 23:08:26 | 2024-11-17 23:08:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void amod(int &x, int y) {
x = x + y >= mod ? x + y - mod : x + y;
}
void dmod(int &x, int y) {
x = x - y < 0 ? x - y + mod : x - y;
}
int ksm(int x, int y = mod - 2) {
int res = 1;
while(y) {
if(y & 1) {
res = 1ll * res * x % mod;
}
y >>= 1;
x = 1ll * x * x % mod;
}
return res;
}
const int maxn = 2005;
const int maxm = 3005;
const int M = 3000;
int n, a[maxn], vis[maxm], tot, prime[maxm], f[maxm];
//int num[maxm], cnt, id[maxm];
//void dfs(int x, int now) {
// if(x == tot + 1) {
// num[++cnt] = now;
// id[now] = cnt;
// return;
// }
// for(int i = now; i <= M / prime[x]; i *= prime[x]) {
// dfs(x + 1, i);
// }
//}
void ins(int val) {
vector<int> p;
for(int i = 1, x = val; i <= tot; i++) {
if(x % prime[i] == 0) {
while(x % prime[i] == 0) {
x /= prime[i];
}
p.push_back(prime[i]);
}
}
int sz = (int)p.size();
vector<int> pi(1 << sz), popcnt(1 << sz);
pi[0] = 1;
for(int s = 1; s < (1 << sz); s++) {
popcnt[s] = __builtin_popcount(s);
for(int i = 0; i < sz; i++) {
if(s >> i & 1) {
pi[s] = pi[s ^ (1 << i)] * p[i];
break;
}
}
}
vector<int> g(1 << sz);
for(int s = (1 << sz) - 1; s >= 0; s--) {
// cout << s << '\n';
g[s] = f[pi[s]];
for(int t = 0; t < (1 << sz); t++) {
if(popcnt[t] > popcnt[s] && ((s & t) == s)) {
dmod(g[s], g[t]);
}
}
}
// cout << sz << ' ' << g[0] << '\n';
vector<int> sum(1 << sz);
for(int s = 0; s < (1 << sz); s++) {
sum[s] = 1;
for(int i = 0; i < sz; i++) {
if(s >> i & 1) {
sum[s] = 1ll * sum[s] * (p[i] - 1) % mod * ksm(p[i]) % mod;
}
}
}
// cout << g[0] << '\n';
int res = 0;
for(int s = 0; s < (1 << sz); s++) {
amod(res, 1ll * g[s] * val % mod * sum[s ^ ((1 << sz) - 1)] % mod);
}
// cout << res << '\n';
for(int s = 0; s < (1 << sz); s++) {
amod(f[pi[s]], res);
}
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vis[1] = 1;
for(int i = 2; i <= M; i++) {
if(!vis[i]) {
prime[++tot] = i;
}
for(int j = 1; j <= tot && prime[j] <= M / i; j++) {
vis[i * prime[j]] = 1;
if(i % prime[j] == 0) {
break;
}
}
}
// num[++cnt] = 1;
// dfs(1, 1);
f[1] = 1;
for(int i = 1; i <= n; i++) {
ins(a[i]);
// for(int j = 1; j <= 6; j++) {
// cout << f[j] << ' ';
// }
// cout << '\n';
}
cout << f[1] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3572kb
input:
5 1 6 8 6 2
output:
700
result:
wrong answer 1st lines differ - expected: '892', found: '700'