QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793713 | #9619. 乘积,欧拉函数,求和 | zhuge0 | WA | 701ms | 5520kb | C++20 | 2.8kb | 2024-11-29 23:16:44 | 2024-11-29 23:16:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
struct dat
{
int mxp;
int s;
int x;
}num[2005]{};
ll n,m,pnum=16;
vector<ll> p{0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,0,0},invp(20);
vector<ll> id((1ll<<16)+5);
ll qpow(ll a,ll b)
{
ll ans=1;
while(b!=0)
{
if(b&1) ans*=a,ans%=mod;
b>>=1;
a*=a;
a%=mod;
}
return ans;
}
void pre()
{
for(int i=1;i<=16;i++)
{
invp[i]=qpow(p[i],mod-2);
id[(ll)pow(2,i-1)]=i;
}
}
//n是2^w
void fenjie(int loc,int x)
{
for(int i=1;i<=16;i++)
{
if(x%p[i]) continue;
num[loc].s|=(1ll<<(i-1));
while(x%p[i]==0)
{
x/=p[i];
}
}
num[loc].mxp=x;
}
void fwt_or(vector<long long>& a,int type,int n) {
for(int x=2;x<=n;x<<=1) {
int k=x>>1;
for(int i=0;i<n;i+=x) {
for(int j=0;j<k;++j) {
if(i+j+k>=n) break;
a[i+j+k]+=(a[i+j]*type+mod)%mod;
a[i+j+k]%=mod;
}
}
}
}
vector<ll> get_f(int l,int r,int mxp)
{
vector<ll> f(1<<16,0),g(1<<16,0);
f[0]=1;
for(int i=l;i<=r;i++)
{
int s=num[i].s;
int x=num[i].x;
for(int j=0;j<(1<<16);j++)
{
int st=s|j;
g[st]=(g[st]+f[j]*x%mod)%mod;
}
for(int j=0;j<(1<<16);j++)
{
f[j]+=g[j];
f[j]%=mod;
g[j]=0;
}
}
if(mxp==1) return f;
ll inv=qpow(mxp,mod-2)%mod;
for(int i=1;i<(1<<16);i++)
{
f[i]=f[i]*(mxp-1)%mod*inv%mod;
}
f[0]=(f[0]-1+mod)%mod*(mxp-1)%mod*inv%mod;
f[0]=(f[0]+1)%mod;
return f;
}
int lowbit(int x)
{
return x&(-x);
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
int temp;
cin>>temp;
num[i].x=temp;
fenjie(i,temp);
}
sort(num+1,num+1+n,[&](dat a,dat b)
{
return a.mxp<b.mxp;
});
vector<ll> e((1<<16),0);
e[0]=1;
fwt_or(e,1,1<<16);
for(int l=1,r=1;l<=n;l=r+1,r=l)
{
while(num[r].mxp==num[l].mxp&&r<n) r++;
vector<ll> f=get_f(l,r,num[l].mxp);
fwt_or(f,1,1<<16);
for(int i=0;i<(1<<16);i++)
{
e[i]=1ll*e[i]*f[i]%mod;
}
}
fwt_or(e,-1,1<<16);
ll ans=0;
for(int i=0;i<(1<<16);i++)
{
int j=i;
ll res=e[i];
while(j!=0)
{
int loc=lowbit(j);
res= res*(p[id[loc]]-1)%mod*(invp[id[loc]])%mod;
res%=mod;
j-=loc;
}
ans+=res%mod;
ans%=mod;
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T=1;
//cin>>T;
pre();
while(T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 9ms
memory: 5432kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 9ms
memory: 5336kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 701ms
memory: 5520kb
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:
950814471
result:
wrong answer 1st lines differ - expected: '50965652', found: '950814471'