QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744832#9619. 乘积,欧拉函数,求和bruteforce_RE 31ms4096kbC++201.6kb2024-11-13 23:43:402024-11-13 23:43:40

Judging History

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

  • [2024-11-13 23:43:40]
  • 评测
  • 测评结果:RE
  • 用时:31ms
  • 内存:4096kb
  • [2024-11-13 23:43:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+7,inf=1e18,mod=998244353,S=15;
vector<int> p={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int power(int x,int t)
{
	int b=1;
	while(t)
	{
		if(t&1)
			b=b*x%mod;
		x=x*x%mod; t>>=1;
	}
	return b;
}
void O_o()
{
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
	}
	vector<vector<array<int,2>>> d(n+1);
	for(int i=1; i<=n; i++)
	{
		int t=a[i],s=0;
		for(int j=0; j<S; j++)
		{
			int x=p[j];
			while(t%p[j]==0)
			{
				t/=p[j];
				s|=(1<<j);
			}
		}
		d[t].push_back({a[i],s});
	}
	vector<array<int,2>> dp(vector<array<int,2>>(1<<S,{0,0}));
	dp[0][0]=1;
//	int now=0;
	for(int T=1; T<=n; T++)
	{
		
		if(!d[T].size()) continue;
		int phi=(T==1?1:(T-1)*power(T,mod-2)%mod);
		bool fir=1;
		for(auto [x,t]:d[T])
		{
			vector<array<int,2>> dpn(vector<array<int,2>>(1<<S,{0,0}));
			for(int s=0; s<(1<<S); s++)
			{
				(dpn[s][0]+=dp[s][0])%=mod;
				(dpn[s][fir^1]+=dp[s][1])%=mod;
				(dpn[s|t][1]+=dp[s][0]*x%mod*phi%mod)%=mod;
				int y=(fir?phi:T);
				(dpn[s|t][1]+=dp[s][1]*x%mod*y%mod)%=mod;
			}
			swap(dp,dpn);
		}
	}
	int ans=0;
	for(int i=0; i<(1<<S); i++)
	{
		int t=1;
		for(int j=0; j<S; j++)
		{
			if((i>>j)&1)
			{
				(t*=(p[j]-1)*power(p[j],mod-2)%mod)%=mod;
			}
		}
		(ans+=(dp[i][0]+dp[i][1])%mod*t%mod)%=mod;
	}
	cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout<<fixed<<setprecision(12);
	int T=1;
//	cin>>T;
	while(T--)
	{
		O_o();
	}
}
/*
3
1 2 3
*/












詳細信息

Test #1:

score: 100
Accepted
time: 31ms
memory: 4044kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 31ms
memory: 4096kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Runtime Error

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:


result: