QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745113 | #9619. 乘积,欧拉函数,求和 | WhybullYMe# | WA | 423ms | 4172kb | C++20 | 2.8kb | 2024-11-14 04:34:12 | 2024-11-14 04:34:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#define ALL(v) v.begin(),v.end()
#define For(i,_) for(int i=0,i##end=_;i<i##end;++i) // [0,_)
#define FOR(i,_,__) for(int i=_,i##end=__;i<i##end;++i) // [_,__)
#define Rep(i,_) for(int i=(_)-1;i>=0;--i) // [0,_)
#define REP(i,_,__) for(int i=(__)-1,i##end=_;i>=i##end;--i) // [_,__)
typedef long long ll;
typedef unsigned long long ull;
#define V vector
#define pb push_back
#define pf push_front
#define qb pop_back
#define qf pop_front
#define eb emplace_back
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define fi first
#define se second
const int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}},inf=0x3f3f3f3f,mod=998244353;
const ll infl=0x3f3f3f3f3f3f3f3fll;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
int init=[](){return cin.tie(nullptr)->sync_with_stdio(false),0;}();
int main(){
int t_case=1;
//scanf("%d",&t_case);
while(t_case--){
int n;
scanf("%d",&n);
V<int>a(n);
for(int &i:a)scanf("%d",&i);
V<int>id(3001,-1),inv(3001),pri;
inv[1]=1;
V<bool>vis(3001);
FOR(i,2,3001){
inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
if(!vis[i]){
id[i]=pri.size();
pri.pb(i);
for(int j=i<<1;j<3001;j+=i)vis[j]=true;
}
}
V<int>coef(1<<16);
coef[0]=1;
For(i,16){
coef[1<<i]=1-inv[pri[i]];
if(coef[1<<i]<0)coef[1<<i]+=mod;
}
For(i,1<<16){
int j=i&-i;
coef[i]=1ll*coef[j]*coef[i^j]%mod;
}
V<array<int,3>>b;
V<int>f(1<<16);
f[0]=1;
For(i,n){
int S=0,x=a[i];
For(j,16)if(x%pri[j]==0){
do x/=pri[j];while(x%pri[j]==0);
S|=1<<j;
}
if(x>1)b.pb({x,S,a[i]});
else Rep(j,1<<16)f[j|S]=(f[j|S]+1ll*f[j]*a[i]%mod*coef[(j|S)^j])%mod;
}
sort(ALL(b));
For(i,b.size()){
int j=i+1;
while(j<b.size()&&b[i][0]==b[j][0])++j;
V<int>g(1<<16);
FOR(k,i,j){
auto [x,y,z]=b[k];
Rep(l,1<<16){
int add=1ll*f[l]*z%mod*coef[(y|l)^y]%mod*(mod+1-inv[x])%mod;
add=(add+1ll*g[l]*z%mod*coef[(y|l)^y])%mod;
if((g[y|l]+=add)>=mod)g[y|l]-=mod;
}
}
For(k,1<<16)if((f[k]+=g[k])>=mod)f[k]-=mod;
i=j-1;
}
int ans=0;
For(i,1<<16)if((ans+=f[i])>=mod)ans-=mod;
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4144kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4144kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 423ms
memory: 4172kb
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:
355225073
result:
wrong answer 1st lines differ - expected: '50965652', found: '355225073'