QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747110 | #9619. 乘积,欧拉函数,求和 | guodong# | WA | 7ms | 4688kb | C++17 | 2.6kb | 2024-11-14 16:21:47 | 2024-11-14 16:21:47 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int allState = 1 << 16;
const int Mod = 998244353;
#define For(i,a,b) for(int i = a; i <= b; ++i)
int Pow(int b,int p = Mod - 2){
int ans = 1;
while(p){
if(p & 1)
ans = ans * b % Mod;
b = b * b % Mod;
p >>= 1;
}
return ans;
}
const int N = 3020;
int F[allState][2];
bool vis[N];
int cnt,Prime[N],Minn[N];
void pre(){
for(int i = 2; i < N; ++i){
if(!vis[i]){
Prime[++cnt] = i;
Minn[i] = i;
}
for(int j = 1; j <= cnt && Prime[j] * i < N; ++j){
vis[i * Prime[j]] = 1;
Minn[i * Prime[j]] = Prime[j];
if(i % Prime[j] == 0)
break;
}
}
}
int State[N],ansc[18];
signed main()
{
#ifdef NICEGUODONG
freopen("data.in","r",stdin);
#endif
ios::sync_with_stdio(false);
pre();
int n;
cin >> n;
// const int prime = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53
// 16 primes <= sqrt(3000)
vector<pair<int,int>> number;
for(int i = 1; i <= 16; ++i)
ansc[i] = (1 - Pow(Prime[i]) + Mod);
For(i,1,n){
int x;
cin >> x;
int tmp = x;
State[x] = 0;
for(int i = 1; i <= 16; ++i){
if(x % Prime[i] == 0){
State[x] |= 1 << (i - 1);
}
while(x % Prime[i] == 0)
x /= Prime[i];
}
number.emplace_back(make_pair(x,tmp));
}
sort(number.begin(),number.end());
int cur = 1;
F[0][0] = 1;
For(i,0,n - 1){
if(number[i].first != cur){
For(s,0,allState - 1){
F[s][0] = (F[s][0] + F[s][1]) % Mod;
F[s][1] = 0;
}
}
int invcur = 0;
if(number[i].first == 1)
invcur = 1;
else
invcur = (1 - Pow(number[i].first) + Mod);
int news = State[number[i].second];
for(int s = allState - 1; s >= 0; --s){
F[s | news][1] = (F[s | news][1] + F[s][1] * number[i].second % Mod + F[s][0] * number[i].second % Mod * invcur % Mod)%Mod;
}
}
For(s,0,allState - 1){
F[s][0] = (F[s][0] + F[s][1]) % Mod;
F[s][1] = 0;
}
int ans = 0;
For(s,0,allState - 1){
int c = 1;
for(int i = 0; i < 16; ++i){
if((1 << i) & s){
c *= ansc[i + 1];
c %= Mod;
}
}
ans += F[s][0] * c % Mod;
ans %= Mod;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 4688kb
input:
5 1 6 8 6 2
output:
1324
result:
wrong answer 1st lines differ - expected: '892', found: '1324'