P8814 [CSP-J 2022] 解密
// ni = pi * qi
// ei * di = pi * qi - pi - qi + 2
// ei * di = ni - pi - qi + 2
// pi + qi = ni - ei * di + 2
// pi * qi = ni
// pi + qi = m
//
// pi * qi = 770
// pi + qi = 770 - 77*5 + 2
// m<=10^9
// m = 10000
// m/2 = 5000 5000*5000 = 25000000
// 10000 = 25000000 - ei * di + 2 = 24990002
// 24990002 = 12495001 * 2
/*
1
25000000 12495001 2 //相同
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
int k;
ll m, ni, di, ei, pi, qi;
int main(){
scanf("%d",&k);
for(int i = 1; i <= k; i++){
scanf("%lld%lld%lld",&ni,&di,&ei);
m = ni - ei * di + 2;
// cout<<m/2<<endl;
bool fl = 0 ;
if(m % 2 == 0 && (m / 2) * (m / 2) == ni){
fl = 1; printf("%lld %lld\n", m/2, m/2);
continue;
}
if(fl == 1) continue;
for(ll pi = 1; pi * pi <= ni; pi++){//pi小
qi = m - pi;
if(pi * qi == ni){
fl = 1; printf("%lld %lld\n", pi, qi);
break;
}
}
if(!fl) printf("NO\n");
}
return 0;
}
标签:ni,P8814,include,ei,di,2022,qi,pi,CSP
From: https://www.cnblogs.com/caterpillor/p/16860240.html