求助 CF1744E1
  • 板块学术版
  • 楼主Unnamed114514
  • 当前回复6
  • 已保存回复6
  • 发布时间2022/10/17 23:01
  • 上次更新2023/10/27 07:03:42
查看原帖
求助 CF1744E1
556362
Unnamed114514楼主2022/10/17 23:01

RT 还没搬到洛谷上来,时限 4s,本地(指令 O2 -lm -std=c++14 -Wall)跑了大约 8s,想知道是不是常数的问题。

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int T,n,t,a,b,c,d,prime[maxn],cnt,p[maxn],num[maxn];
bool flg[maxn];
inline void Prime(int n){
	flg[0]=flg[1]=1;
	for(int i=2;i<=n;++i){
		if(!flg[i]){
			prime[++cnt]=i;
			p[i]=cnt;
		}
		for(int j=1;j<=cnt&&i*prime[j]<=n;++j){
			flg[i*prime[j]]=1;
			p[i*prime[j]]=j;
			if(i%prime[j]==0)
				break;
		}
	}
}
int main(){
	Prime(100000);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		t=a;
		while(t!=1){
			++num[p[t]];
			t/=prime[p[t]];
		}
		t=b;
		while(t!=1){
			++num[p[t]];
			t/=prime[p[t]];
		}
		bool flg=1;
		for(int x=a+1;x<=c;++x){
			t=x;
			while(t!=1){
				--num[p[t]];
				t/=prime[p[t]];
			}
			bool oh=1;
			int res=1;
			for(int i=1;i<=cnt;++i)
				for(int j=1;j<=num[i];++j){
					if(res>d/prime[i]){
						oh=0;
						break;
					}
					res*=prime[i];
				}
			t=x;
			while(t!=1){
				++num[p[t]];
				t/=prime[p[t]];
			}
			if(oh&&res<=d&&(b+res)/res*res<=d){
				printf("%d %d\n",x,(b+res)/res*res);
				flg=0;
				break;
			}
		}
		if(flg)
			puts("-1 -1");
		t=a;
		while(t!=1){
			--num[p[t]];
			t/=prime[p[t]];
		}
		t=b;
		while(t!=1){
			--num[p[t]];
			t/=prime[p[t]];
		}
	}
	return 0;
}
2022/10/17 23:01
加载中...