QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#736701#9619. 乘积,欧拉函数,求和ucup-team4352#TL 7ms5428kbC++231.7kb2024-11-12 12:43:252024-11-12 12:43:25

Judging History

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

  • [2024-11-12 12:43:25]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:5428kb
  • [2024-11-12 12:43:25]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define log(x) (31^__builtin_clz(x))
#define lowbit(x) (x&-x)
using namespace std;
const int maxn=3005,p=998244353;
vector<int>y[maxn];
int notpri[maxn],ct[maxn];
int qr[maxn];
ll num[30],inv[30];
void init() {
	int n=3000;
	int tot=0;
	y[1]={0};
	for(int i=2;i<=n;i++){
		if(notpri[i])continue;
		if(tot>16)tot=16;
		ct[i]=tot;
		num[tot]=i;
		tot++;
		for(int j=i;j<=n;j+=i){
			y[j].push_back(i);
			notpri[j]=1;
			qr[j]|=1<<ct[i];
		}
	}
}
ll qpow(ll x,ll y){
	ll s=1;
	while(y){
		if(y&1)s=s*x%p;
		x=x*x%p;
		y>>=1;
	}
	return s;
}
ll a[3005];
ll add[(1<<17)+5];
bool cmp(int a,int b){
	return y[a].back()<y[b].back();
}
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	vector<int>dp1((1<<17)+5),dp2;
	dp1[0]=1;
	for(int i=1;i<=n;i++){
		if(i>1&&y[a[i]].back()>54&&y[a[i]].back()!=y[a[i-1]].back()){
			for(int j=(1<<16);j<(1<<17);j++){
				dp1[j^(1<<16)]+=dp1[j];
				if(dp1[j^(1<<16)]>=p)dp1[j^(1<<16)]-=p;
				dp1[j]=0;
			}
		}
		if(y[a[i]].size())num[16]=y[a[i]].back();
		add[0]=1;
		for(int j=0;j<17;j++){
			inv[j]=qpow(num[j],p-2);
		}
		for(int j=1;j<(1<<17);j++){
			add[j]=add[j^lowbit(j)]*(num[log(lowbit(j))]-1)%p*inv[log(lowbit(j))]%p;
		}
		dp2=dp1;
		for(int j=0;j<(1<<17);j++){
			dp2[j|qr[a[i]]]=(dp2[j|qr[a[i]]]+dp1[j]*add[qr[a[i]]^(j&qr[a[i]])]%p*a[i]%p)%p;
		}
		dp1=dp2;
	}
	ll ans=0;
	for(auto u:dp1)ans+=u;
	cout<<ans%p<<"\n";
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	init();
	int t=1;
	// cin>>t;
	while(t--)solve();
	return 0;
}
/*
8
500 500 1 1 1 1 1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 5420kb

input:

5
1 6 8 6 2

output:

892

result:

ok single line: '892'

Test #2:

score: 0
Accepted
time: 6ms
memory: 5428kb

input:

5
3 8 3 7 8

output:

3157

result:

ok single line: '3157'

Test #3:

score: -100
Time Limit Exceeded

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:

50965652

result: