40pts求助 悬关(TLE+WA)
查看原帖
40pts求助 悬关(TLE+WA)
652816
saixingzhe楼主2023/4/2 21:14

提交记录

#include<bits/stdc++.h>
using namespace std;
int n,m1,m2,t[450000],ts[450000],s,ti,cun,lastans=2147483647,lastflag,tscun;
int main(){
	scanf("%d%d%d",&n,&m1,&m2);
	ti=m1;
	for(int j=2;j<=sqrt(m1);j++){
		int cnt=0;
		while(m1%j==0&&m1)	cnt++,m1/=j;
		t[j]=cnt;	 
	}
	if(m1>1)	t[m1]=1*m2;
	cun=m1;
	m1=ti;
	for(int j=2;j<=sqrt(m1);j++){
		t[j]*=m2;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&s);
		ti=s;	 
		for(int j=2;j<=sqrt(s);j++){
			int cnt=0;
			while(s%j==0&&m1)	cnt++,s/=j;
			ts[j]=cnt;	 
		}
		if(s>1)	ts[s]=1;
		tscun=s;
		s=ti;
		bool flag=0; 
		int ans=0;
		for(int j=2;j<=sqrt(m1);j++){
			if(!t[j])	continue;
			if(t[j]&&!ts[j]){
				flag=1;
				break;
			}	
			ans=max(ans,t[j]-ts[j]);
		}
		if(cun>1){
			if(t[cun]&&!ts[cun])	flag=1;
			else	ans=max(ans,t[cun]-ts[cun]);
		}
		if(tscun>1)	ts[tscun]=0;
		for(int j=2;j<=sqrt(s);j++)	ts[j]=0;
		if(!flag) lastflag=1,lastans=(min(lastans,ans));
	}
	if(!lastflag)	printf("-1\n");
	else	printf("%d\n",lastans+1);
	return 0;
}

救救孩子吧,求求了

2023/4/2 21:14
加载中...