QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738540 | #9619. 乘积,欧拉函数,求和 | wxy2005# | WA | 1167ms | 14180kb | C++14 | 2.1kb | 2024-11-12 19:19:04 | 2024-11-12 19:19:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(i=j;i<=k;++i)
#define dow(i,j,k) for(i=j;i>=k;--i)
#define pr pair
#define mkp make_pair
#define fi first
#define se second
const int N=3e3+10;
#define LL long long
const LL md=998244353;
int n,prm[N],pcnt,vis[N];
LL a[N],dv[1<<18],iv[N];
LL fpw(LL x,LL y){
LL res=1;
while(y){
if(y&1)res=res*x%md;
x=x*x%md;y>>=1;
}
return res;
}
vector<pr<LL,int> >t[N];
LL inv(LL x){return iv[x] ? iv[x]:iv[x]=fpw(x,md-2);}
LL f[1<<18],g[2][1<<18];
int main(){
//freopen("in.txt","r",stdin);
scanf("%d",&n);
int i,j,k;
rep(i,1,n)scanf("%lld",&a[i]);
rep(i,2,3000){
if(!vis[i]){
prm[++pcnt]=i;
}
for(j=1;j<=pcnt && prm[j]*i<=3000;++j){
vis[prm[j]*i]=1;if(i%prm[j]==0)break;
}
}
rep(i,1,n){
rep(j,17,pcnt)if(a[i]%prm[j]==0){
int S=0;
rep(k,0,15)if(a[i]%prm[k+1]==0)S|=1<<k;
t[j-16].push_back(mkp(a[i],S));
break;
}
if(j>pcnt){
int S=0;
rep(k,0,15)if(a[i]%prm[k+1]==0)S|=1<<k;
t[0].push_back(mkp(a[i],S));
}
}
rep(i,0,(1<<16)-1){
dv[i]=1;
rep(j,1,16)if((1<<j-1)&i)dv[i]=dv[i]*(1ll-inv(prm[j])+md)%md;
}
f[0]=1;
for(auto v:t[0]){
vector<LL>nw(1<<18,0ll);
rep(i,0,(1<<16)-1)nw[i]=f[i];
rep(i,0,(1<<16)-1)nw[i|v.se]=(nw[i|v.se]+f[i]*v.fi%md*dv[v.se-(v.se&i)]%md)%md;
rep(i,0,(1<<16)-1)f[i]=nw[i];
//cerr<<f[0]<<' '<<f[1]<<' '<<f[2]<<' '<<f[3]<<'\n';
}
rep(j,17,pcnt){
rep(i,0,(1<<16)-1){
g[0][i]=f[i];
g[1][i]=0;
}
for(auto v:t[j-16]){
vector<LL>nw[2];
nw[0].assign(1<<18,0ll);
nw[1].assign(1<<18,0ll);
rep(i,0,(1<<16)-1){
nw[0][i]=g[0][i];
nw[1][i]=g[1][i];
}
rep(i,0,(1<<16)-1){
nw[1][i|v.se]=(nw[1][i|v.se]+g[1][i]*v.fi%md*dv[v.se-(v.se&i)]%md)%md;
nw[1][i|v.se]=(nw[1][i|v.se]+g[0][i]*v.fi%md*dv[v.se-(v.se&i)]%md*(1ll-inv(prm[j])+md)%md)%md;
nw[0][i|v.se]=(nw[0][i|v.se]+g[0][i]*v.fi%md*dv[v.se-(v.se&i)]%md)%md;
}
rep(i,0,(1<<16)-1){
g[0][i]=nw[0][i];
g[1][i]=nw[1][i];
}
}
rep(i,0,(1<<16)-1)f[i]=(g[0][i]+g[1][i])%md;
}
LL ans=0;
rep(i,0,(1<<16)-1)ans=(ans+f[i])%md;
printf("%lld",ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 58ms
memory: 12904kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 51ms
memory: 12464kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 1167ms
memory: 14180kb
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:
246298275
result:
wrong answer 1st lines differ - expected: '50965652', found: '246298275'