QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#760535 | #9619. 乘积,欧拉函数,求和 | Afterlife# | WA | 61ms | 4432kb | C++20 | 2.0kb | 2024-11-18 17:25:06 | 2024-11-18 17:25:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool p[65];
vector<int> pr;
int n ;
int a[2005];
typedef pair<int,int> pii;
map<int,vector<pii> > mp;
int f[1 << 16] , g[1 << 16];
const int mod = 998244353;
int fpow(int a,int b) {
int ans = 1;
while(b) {
if(b & 1) ans = 1LL * ans * a % mod;
a = 1LL * a * a %mod ; b >>= 1;
}
return ans;
}
void solv() {
for(int i = 2;i <= 55;i++) {
if(!p[i]) {
pr.push_back(i) ;
for(int j = i * 2;j <= 55;j += i) p[j] = 1;
}
}
cin >> n;
for(int i = 1;i <= n;i++) {
cin >> a[i] ;
int d = a[i];
int m = 0;
for(int j = 0;j < pr.size();j++) {
int x = pr[j];
if(d % x == 0) {
while(d % x == 0) d /= x;
m |= (1 << j) ;
}
}
mp[d].push_back({m , a[i]}) ;
}
f[0] = 1;
for(auto &[p,v] : mp) {
memcpy(g , f , sizeof(f));
for(auto [x,a] : v) {
printf("%d : %d %d\n",p,x,a) ;
for(int i = (1 << pr.size()) - 1; i >= 0;i--) {
g[i | x] = (g[i | x] + 1LL * g[i] * a) % mod;
}
}
int z = 1LL * (p - 1) * fpow(p , mod - 2) % mod;
if(p == 1) z = 1;
for(int i = 0;i < (1 << pr.size()) ; i++) {
g[i] = (g[i] - f[i] + mod) % mod;
f[i] = (f[i] + 1LL * g[i] * z) % mod;
// if(i <= 3) printf("I %d %d , %d , %d\n",i,g[i] , f[i] , z);
}
}
// cerr << pr.size() << '\n';
int ans = 0;
for(int i = 0;i < (1<<pr.size()) ; i++) {
int z = 1;
for(int j = 0;j < pr.size();j++) {
if((i >> j) & 1) {
z = 1LL * z * (pr[j] - 1) % mod * fpow(pr[j] , mod - 2) % mod;
}
}
ans = (ans + 1LL * f[i] * z) % mod ;
}
cout << ans << '\n';
return ;
}
int main() {
ios::sync_with_stdio(false) ; cin.tie(0) ;
int t = 1;
while(t--) solv() ;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 61ms
memory: 4432kb
input:
5 1 6 8 6 2
output:
892 1 : 0 1 1 : 3 6 1 : 1 8 1 : 3 6 1 : 1 2
result:
wrong output format Extra information in the output file