QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764368#9619. 乘积,欧拉函数,求和HanghangWA 311ms5372kbC++201.3kb2024-11-20 08:51:222024-11-20 08:51:36

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 08:51:36]
  • 评测
  • 测评结果:WA
  • 用时:311ms
  • 内存:5372kb
  • [2024-11-20 08:51:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N=3003,M=(1<<16)+3,V=(1<<16)-1,H=998244353;
ll n,ans,cnt,a[N],b[N],pri[N],num[N],iv[M],sum[M],F[M],G[M];
bool vis[N];
vector<int>ve[N];
ll Val(ll x){return (x-1)*iv[x]%H;}
void Init()
{
	for(int i=2;i<N;i++)
	{
		if(!vis[i])pri[++cnt]=i,num[i]=cnt;
		for(int j=1;j<=cnt&&pri[j]*i<N;j++)
		{
			vis[pri[j]*i]=1;
			if(i%pri[j]==0)break;
		}
	}
	iv[0]=iv[1]=sum[0]=1;
	for(int i=2;i<N;i++)iv[i]=H-H/i*iv[H%i]%H;
	for(int i=1;i<=V;i++)sum[i]=sum[i-(i&-i)]*Val(pri[__lg(i&-i)+1])%H;
}
void Add(ll &x,ll y){x=(x+y)%H;}
void Sol(ll *f,const vector<int> &now)
{
	for(int i=0;i<=V;i++)f[i]=i==0;
	for(int id:now)
		for(int i=V;i>=0;i--)Add(f[i|b[id]],f[i]*a[id]);
}
int main()
{
	cin>>n;Init();
	for(int i=1,x;i<=n;i++)
	{
		cin>>x,a[i]=x;
		for(int j=1;j<=cnt&&pri[j]<=53;j++)if(x%pri[j]==0)
		{
			b[i]|=1<<(j-1);
			while(x%pri[j]==0)x/=pri[j];
		}
		if(x>1)ve[x].push_back(i);
	}
	vector<int>cur(n,0);iota(cur.begin(),cur.end(),1);
	Sol(F,cur);
	for(int t=1;t<=cnt;t++)if(pri[t]>53&&ve[pri[t]].size())
	{
		Sol(G,ve[pri[t]]);
		for(int i=1;i<=V;i++)F[i]=(F[i]-G[i]+H)%H;
		for(int i=1;i<=V;i++)Add(ans,G[i]*sum[i]%H*Val(pri[t])); 
	}
	for(int i=0;i<=V;i++)Add(ans,F[i]*sum[i]);
	cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4944kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 2ms
memory: 4600kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Wrong Answer
time: 311ms
memory: 5372kb

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:

138739640

result:

wrong answer 1st lines differ - expected: '50965652', found: '138739640'