QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740405 | #9619. 乘积,欧拉函数,求和 | jr_zch | WA | 221ms | 218288kb | C++14 | 1.6kb | 2024-11-13 09:45:54 | 2024-11-13 09:46:13 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3e3+7,maxp=5e2+7,maxs=1<<16,mod=998244353;
const int p[60]={0,2,3,5,7,11,13,17,23,29,31,37,41,43,47,51,53};
int n,ans;
int a[maxn],w[maxn],f[maxp][maxs],g[maxs],h[maxs];
vector<int> big;
vector<int> e[maxn];
/*
f[i+1][s] <- f[i][s]
f[i+1][s^w[i+1]] <- f[i][s]*a[i+1]
*/
int _mod(int x){
return x>=mod?x-mod:x;
}
int qpow(int x,int y){
if(!y) return 1;
if(y==1) return x;
int val=qpow(x,y>>1ll);
if(y&1ll) return val*val%mod*x%mod;
else return val*val%mod;
}
void calc(int x){
int now=x;
for(int i=1;i<=16;i++){
if(!(now%p[i])){
w[x]|=1<<i-1;
while(!(now%p[i])) now/=p[i];
}
}
e[now].push_back(x);
big.push_back(now);
return ;
}
signed main(){
for(int s=0;s<maxs;s++){
h[s]=1;
for(int i=0;i<16;i++){
if(s&1<<i) h[s]=h[s]*(p[i+1]-1)%mod*qpow(p[i+1],mod-2)%mod;
}
}
scanf("%lld",&n);
int cnt=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
if(a[i]!=1) calc(a[i]);
else cnt++;
}
sort(big.begin(),big.end());
big.erase(unique(big.begin(),big.end()),big.end());
int tot=big.size();
f[0][0]=1;
for(int i=0;i<tot;i++){
int num=big[i];
int mul=(num-1)*qpow(num,mod-2)%mod;
if(num==1) mul=1;
for(int s=0;s<maxs;s++) g[s]=f[i][s]*mul%mod;
for(int j=0;j<e[num].size();j++){
int val=e[num][j];
for(int s=maxs-1;s>=0;s--){
g[s|w[val]]=(g[s|w[val]]+g[s]*val)%mod;
}
}
for(int s=0;s<maxs;s++) f[i+1][s]=(f[i][s]+g[s]-f[i][s]*mul%mod+mod)%mod;
}
for(int s=0;s<maxs;s++) ans=(ans+f[tot][s]*h[s])%mod;
printf("%lld",ans*qpow(2,cnt)%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 100ms
memory: 6212kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 104ms
memory: 6176kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: 0
Accepted
time: 221ms
memory: 218288kb
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:
50965652
result:
ok single line: '50965652'
Test #4:
score: -100
Wrong Answer
time: 219ms
memory: 218120kb
input:
2000 1 1 1 1 1 1 1 1 353 1 1 1 557 1 1 1 1 1 1 1 1 1 1 1 1423 1 1 1327 1 1 1 907 1 1 1 1 1 2971 1 1 1 2531 1 1 1 1 1 1 1 1 1 2099 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199 2999 1 727 1 1 1 1 1 1 1 71 1 1 1 1 1 1 2503 1 176 1 1 1 1 1 1 1361 1013 1 1 1 1 1 1 1 2699 1 1 1 1 1 1 1 1 1 2897 1 1 1 1 1637 1 1 1367 1...
output:
829569917
result:
wrong answer 1st lines differ - expected: '420709530', found: '829569917'