QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743929 | #9619. 乘积,欧拉函数,求和 | _fcy_ | WA | 778ms | 12360kb | C++14 | 3.1kb | 2024-11-13 20:21:04 | 2024-11-13 20:21:06 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int maxn=1e5+10;
const int mod=998244353;
int n;
int f[maxn][2];
int jie[maxn],inv[maxn],factinv[maxn];
void init_ny(int x)
{
factinv[0]=1; jie[0]=1;
factinv[1]=1; inv[1]=1; jie[1]=1;
for(int i=2;i<=x;i++)
{
inv[i]=(mod-mod/i)*inv[mod%i];
inv[i]%=mod;
jie[i]=jie[i-1]*i;
jie[i]%=mod;
factinv[i]=factinv[i-1]*inv[i];
factinv[i]%=mod;
}
}
pair<int,int> a[maxn];
vector <int> minp,primes;
vector <int> ver[maxn];
void sieve(int n){
minp.assign(n+1,0);
primes.clear();
for(int i=2;i<=n;i++){
if (minp[i]==0){
minp[i]=i;
primes.push_back(i);
}
for(auto p:primes){
if(i*p>n){
break;
}
minp[i*p]=p;
if(p==minp[i]){
break;
}
}
}
}
int pr[maxn],rnk[maxn];
int add(int x,int y){
x+=y; x%=mod; return x;
}
int mul(int x,int y){
x*=y; x%=mod; return x;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
sieve(3005); init_ny(3005);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].se;
int mx=1,x=a[i].se;
while(x>1){
mx=max(mx,minp[x]);
x/=minp[x];
}
a[i].fi=mx;
}
sort(a+1,a+n+1);
int piv=54;
for(int i=1;i<=n;i++){
int x=a[i].se;
while(x>1){
int tmp=minp[x];
while(x%tmp==0){
x/=tmp;
}
if(tmp<piv) ver[i].push_back(tmp);
}
}
int cnt=0;
for(auto u:primes){
if(u>54) break;
rnk[u]=cnt;
cnt++;
}
//cout<<rnk[3]<<endl;
f[0][0]=1;
for(int i=1;i<=n;i++){
if(a[i].fi!=a[i-1].fi){
for(int j=0;j<(1<<cnt);j++){
f[j][0]=add(f[j][0],f[j][1]);
f[j][1]=0;
}
}
for(int j=(1<<cnt)-1;j>=0;j--){
for(int k=1;k>=0;k--){
int nj=j,nk=k,val=f[j][k];
val=mul(val,a[i].se);
for(auto u:ver[i]){
if(u<piv){
if(~j>>rnk[u]&1){
nj|=(1<<rnk[u]);
val=mul(val,mul(u-1,inv[u]));
}
}
else{
if(nk==0){
val=mul(val,mul(u-1,inv[u]));
}
nk=1;
}
}
// if(k==0&&j==0){
// cout<<i<<" "<<j<<" "<<k<<" "<<nj<<" "<<nk<<" "<<val<<endl;
// }
f[nj][nk]=add(f[nj][nk],val);
}
}
}
int ans=0;
for(int i=0;i<(1<<cnt);i++){
for(int j=0;j<=1;j++){
ans=add(ans,f[i][j]);
// if(i<=16) cout<<i<<" "<<j<<" "<<f[i][j]<<endl;
}
}
cout<<ans<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12236kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 6ms
memory: 12264kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 778ms
memory: 12360kb
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:
138739741
result:
wrong answer 1st lines differ - expected: '50965652', found: '138739741'