QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740330 | #9619. 乘积,欧拉函数,求和 | nb_jzy | WA | 132ms | 4848kb | C++20 | 1.5kb | 2024-11-13 09:01:14 | 2024-11-13 09:01:14 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=3005,maxs=17,mod=998244353;
int a[maxn],cnt=-1,n,len,f[1<<maxs],ny[maxn],s[maxn],prime[22],pro[1<<maxs];
vector<int> g[maxn];
int poww(int x,int y){
int res=1;
while(y>0){
if(y&1){
res=res*x%mod;
}
x=x*x%mod;
y>>=1;
}
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
for(int i=1;i<=3000;i++){
ny[i]=poww(i,mod-2);
}
for(int i=2;i<=55;i++){
bool f=1;
for(int j=2;j*j<=i;j++){
if(i%j==0){
f=0;
break;
}
}
if(f){
cnt++;
prime[cnt]=i;
}
}
cnt++;
cin>>n;
int len=(1<<cnt)-1;
for(int i=0;i<=len;i++){
pro[i]=1;
for(int j=0;j<cnt;j++){
if((i>>j)&1){
pro[i]=(prime[j]-1)*pro[i]%mod*ny[prime[j]]%mod;
}
}
}
int cntt=0;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]==1){
cntt++;
continue;
}
int xx=a[i];
for(int j=0;j<cnt;j++){
while(xx%prime[j]==0){
s[i]|=(1<<j);
xx/=prime[j];
}
}
g[xx].push_back(i);
}
int ans=1;
for(int i=1;i<=3000;i++){
sort(g[i].begin(),g[i].end());
if(g[i].empty()){
continue;
}
for(int j=0;j<=len;j++){
f[j]=0;
}
f[0]=1;
for(auto v:g[i]){
for(int j=len;j>=0;j--){
f[j|s[v]]=(f[j]*a[v]+f[j|s[v]])%mod;
}
}
int res=0;
for(int j=0;j<=len;j++){
res=(f[j]*pro[j]+res)%mod;
}
if(i>1){
res=res*ny[i]%mod*(i-1)%mod;
}
ans=ans*res%mod;
}
cout<<ans*poww(2,cntt)%mod;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 4712kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 4772kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 132ms
memory: 4848kb
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:
508601007
result:
wrong answer 1st lines differ - expected: '50965652', found: '508601007'