要将 ax2+bx+c分解为 (a1x+b1)(a2x+b2)的形式,输出a1,a2,b1,b2,否则输出NO
(a1x+b1)(a2x+b2)=a1a2x²+(a1b2+a2b1)x+b1b2,所以a=a1a2,b=a1b2+a2b1,c=b1b2
#include<bits/stdc++.h>
using namespace std;
void sol(){
int a,b,c;cin>>a>>b>>c;
for(int i=-1000;i<=1000;i++){
if(i==0||a%i!=0)continue;
for(int j=-1000;j<=1000;j++){
if(j==0||c%j!=0)continue;
int a2=a/i,b2=c/j;
if(i*b2+a2*j==b){
cout<<i<<" "<<j<<" "<<a2<<" "<<b2<<endl;
return;
}
}
}
cout<<"NO"<<endl;
}
int main(){
int t;cin>>t;
while(t--)sol();
}