QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#746928 | #9619. 乘积,欧拉函数,求和 | IllusionaryDominance# | WA | 198ms | 4424kb | C++20 | 2.2kb | 2024-11-14 15:53:06 | 2024-11-14 15:53:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
const int N = 2005;
const int M = 3005;
const int p = 998244353;
int pr[3005],tot,mk[3005],mi[3005];
int inv[3005], id[M], a[N], b[N], c[N], rk[N];
// 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53
void init()
{
for (int i=(inv[0]=inv[1]=1)+1; i<M; ++i) inv[i]=(ll)(p-p/i)*inv[p%i]%p;
for (int i=2;i<M;++i)
{
if (!mk[i]) { pr[++tot] = i; mi[i]=i; id[i]=tot;}
for (int j=1; j<=tot&&(ll)pr[j]*i<M; ++j)
{
mk[pr[j]*i]=1; mi[pr[j]*i]=pr[j];
if (i%pr[j]==0) break;
}
}
// for(int i=1;i<=16;++i) cout<<pr[i]<<",";
}
int upd[1<<16|5], f[1<<16|5], mo[1<<16|5];
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
init();
int n; cin>>n;
mo[0] = 1;
int all=1<<16;
for(int i = 1; i < all; ++i)
{
int j=i&-i; int idj=31-__builtin_clz(j);
mo[i] = (ll)mo[i^j]*inv[pr[idj+1]]%p*(pr[idj+1]-1)%p;
}
for (int i=1; i<=n; ++i)
{
cin>>a[i];
int x=a[i];
b[i] = 0;
c[i] = 1;
rk[i] = i;
while(x != 1)
{
int y=mi[x];
if(id[y]<=16)
{
b[i]|=(1<<(id[y]-1));
}
else c[i]*=y;
while(x%y==0) x/=y;
}
}
sort(rk+1, rk+n+1, [&](int x, int y) -> bool { return c[x] < c[y]; });
f[0] = 1;
for (int i=1; i<=n; ++i)
{
int j=i;
vector<int> tmp; tmp.push_back(rk[i]);
int C=c[rk[i]];
while(j+1<=n && c[rk[j+1]]==C) tmp.push_back(rk[++j]);
// all
for(int s=0; s<all; ++s) upd[s]=f[s];
for(auto I : tmp)
{
for(int s=all-1; s>=0; --s) if(f[s])
{
(f[s|b[I]]+=(ll)f[s]*a[I]%p)%=p;
}
}
if (C!=1)
{
for(int s=0; s<all; ++s) f[s]=(upd[s]+(ll)((f[s]-upd[s])%p+p)%p*(C-1)*inv[C]%p)%p;
}
i=j;
}
int ans=0;
for(int i=0;i<all;++i) (ans+=((ll)f[i]*mo[i]%p))%=p;
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4136kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 2ms
memory: 4204kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 198ms
memory: 4424kb
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:
-134486004
result:
wrong answer 1st lines differ - expected: '50965652', found: '-134486004'