60分求助[CSP-J 2022 解密]
  • 板块灌水区
  • 楼主LHT20091205
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/4/7 19:47
  • 上次更新2023/10/23 19:10:12
查看原帖
60分求助[CSP-J 2022 解密]
745175
LHT20091205楼主2023/4/7 19:47

原题链接

#include <iostream>
#include <sstream>
#include <cmath>
#define ll long long
using namespace std;
ll k1,k2;
ll s[10005];
int head=0;

ll f(ll left,ll right,ll n,ll e,ll d){
	ll a,b;
	while (left<=right){
		ll mid=(left+right)/2;
		a=s[mid];
		b=n/s[mid];
		if (e*d==(a-1)*(b-1)+1){
			return a;
		}
		if ((a-1)*(b-1)+1<=e*d) left=mid+1;
		else right=mid-1;
	}
	return -1;
}

int main(){
	//freopen("decode4.in","r",stdin);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin>>t;
	while (t--){
		head=0;
		ll n,e,d;
		cin>>n>>e>>d;
		for (int i=1;i<=sqrt(n);i++){
			if (n%i==0) s[++head]=i;
		}
		ll k1=f(1,head,n,e,d);
		if (k1!=-1){
			ll k2=n/k1;
			cout <<k1<<' '<<k2<<endl;
		}else cout <<"NO"<<endl;
	}
	return 0;
}

RT

2023/4/7 19:47
加载中...