QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#737011 | #9619. 乘积,欧拉函数,求和 | nudun | WA | 1764ms | 5436kb | C++14 | 2.4kb | 2024-11-12 14:14:49 | 2024-11-12 14:14:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void MAX(T &a,T b){if(b>a)a=b;}
template<class T>inline void MIN(T &a,T b){if(b<a)a=b;}
template<class T>inline void rd(T &x){
x=0;char o,f=1;
while(o=getchar(),o<48)if(o=='-')f=-f;
do x=(x<<3)+(x<<1)+(o^48);
while(o=getchar(),o>47);
x*=f;
}
const int M=3005;
const int S=1<<16;
const int P=998244353;
int fast(int a,int b=P-2){
int res=1;
while(b){
if(b&1)res=1ll*res*a%P;
a=1ll*a*a%P;
b>>=1;
}
return res;
}
int n,A[M],s[M],mx[M],p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
int f[S],g[S],dp[2][S][2];
bool cmp(int a,int b){
return mx[a]<mx[b];
}
void add(int &a,ll b){
a=(a+b)%P;
}
void solve(){
for(int i=1;i<M;i++){
int x=i;
for(int j=0;j<16;j++)while(x%p[j]==0)x/=p[j];
if(x>1)mx[i]=x;
}
cin>>n;
for(int i=1;i<=n;i++)cin>>A[i];
sort(A+1,A+1+n,cmp);
for(int i=1;i<=n;i++){
for(int j=0;j<16;j++)if(A[i]%p[j]==0)s[i]|=1<<j;
}
for(int i=0;i<S;i++){
f[i]=1;
for(int j=0;j<16;j++)if(i>>j&1)f[i]=1ll*f[i]*(1-fast(p[j])+P)%P;
g[i]=fast(f[i]);
}
dp[0][0][0]=1;
for(int i=1;i<=n;i++){
int cur=i&1;
for(int j=0;j<S;j++)dp[cur][j][0]=dp[cur][j][1]=0;
for(int j=0;j<S;j++){
if(s[i]==s[i-1]){
if(s[i]){
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][0]*A[i]%P*g[j]%P*f[j|s[i]]%P*(1-fast(mx[A[i]])+P));
}
else{
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][0]*A[i]%P*g[j]%P*f[j|s[i]]);
}
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][1]*A[i]%P*g[j]%P*f[j|s[i]]);
add(dp[cur][j][0],dp[!cur][j][0]);
add(dp[cur][j][1],dp[!cur][j][1]);
}
else{
if(s[i]){
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][0]*A[i]%P*g[j]%P*f[j|s[i]]%P*(1-fast(mx[A[i]])+P));
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][1]*A[i]%P*g[j]%P*f[j|s[i]]%P*(1-fast(mx[A[i]])+P));
}
else{
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][0]*A[i]%P*g[j]%P*f[j|s[i]]);
add(dp[cur][j|s[i]][1],1ll*dp[!cur][j][1]*A[i]%P*g[j]%P*f[j|s[i]]);
}
add(dp[cur][j][0],dp[!cur][j][0]);
add(dp[cur][j][0],dp[!cur][j][1]);
}
}
}
int ans=0;
for(int i=0;i<S;i++)ans=(1ll*ans+dp[n&1][i][0]+dp[n&1][i][1])%P;
printf("%d\n",ans);
}
int main(){
#ifndef ONLINE_JUDGE
// freopen("nudun.in","r",stdin);
// freopen("nudun.out","w",stdout);
#endif
int cas=1;
// rd(cas);
while(cas--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 143ms
memory: 5436kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 159ms
memory: 5408kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 1764ms
memory: 5408kb
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:
204885467
result:
wrong answer 1st lines differ - expected: '50965652', found: '204885467'