QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757892 | #9619. 乘积,欧拉函数,求和 | rdcamelot | WA | 0ms | 3948kb | C++20 | 1.8kb | 2024-11-17 14:24:12 | 2024-11-17 14:24:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;
constexpr int mod=998244353;
constexpr int pr[16]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
//pr的逆元
constexpr int ipr[16]={499122177, 665496236, 399297742, 142606337, 725995894, 537516191, 58720257, 893166001, 781234712, 516333287, 869438631, 755428160, 900854661, 487514685, 807091180};
constexpr int N=1<<15;
void solve(){
int n;
cin>>n;
vector<int> a(n);
vector<int> msk(n);
vector<vector<int>> w(3005);
for(int i=0;i<n;i++){
cin>>a[i];
int x=a[i],y=0;
for(int j=0;j<15;j++){
while(x%pr[j]==0){
x/=pr[j];
}
y|=1<<j;
}
if(x==2809){
x=53;
}
msk[i]=y;
w[x].emplace_back(i);
}
vector<i64> dp(N);
dp[0]=1ll;
for(int i=1;i<=3000;i++){
if(!w[i].empty()){
vector<i64> ndp(N);
for(int j:w[i]){
int sk=msk[j];
int val=a[j];
int vv= i==1?a[j]:a[j]/i*(i-1);
for(int k=N-1;k>=0;k--){
ndp[k|sk]=(ndp[k|sk]+ndp[k]*val+dp[k]*vv)%mod;
}
}
for(int j=0;j<N;j++){
dp[j]=(dp[j]+ndp[j])%mod;
}
}
}
i64 ans=dp[0];
vector<i64> ip(N);
ip[0]=1ll;
for(int i=1;i<N;i++){
int z=__builtin_ctz(i);
ip[i]=ip[i^1<<z]*ipr[z]%mod;
ans+=dp[i]*ip[i]%mod;
}
ans%=mod;
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3948kb
input:
5 1 6 8 6 2
output:
59588056
result:
wrong answer 1st lines differ - expected: '892', found: '59588056'