代码如下
// Problem: P8814 [CSP-J 2022] 解密
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P8814
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 10;
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int k;cin>>k;
while(k--)
{
int n,d,e;cin>>n>>d>>e;
bool f=false;
for(int q=1;q<=1e5;q++)
{
// 二分查找p
ll l=0,r=1e9;
ll p=-1;
ll mid=(l+r)>>1;
while(l+1!=r)
{
mid=(l+r)>>1;
if(mid*q>n)r=mid;
else if(mid*q<n) l=mid;
else {
p=mid;
break;
}
}
// cerr<<p<<' '<<q<<'\n';
if(p==-1 || (p-1)*(q-1)+1!=e*d){continue;}
else {f=true;cout<<q<<" "<<p<<'\n';break;}
}
if(!f)cout<<"NO"<<'\n';
}
return 0;
}