#include<iostream>
#include<map>
#include<cstdio>
#include<cmath>
using namespace std;
int T , M;
bool check(int a , int b , int c){
if(pow(b,2) - 4 * a * c < 0){
return false;
}
return true;
}
int gcd(int a , int b){
if(a % b == 0) return b;
return gcd(b , a % b);
}
bool check(int a ,int b ,int c , int x){
if(a * pow(x , 2) + b * x + c * x == 0) return true;
return false;
}
void print_num(int k , int num){
int ret = 1;
int numkk = k;
for(int i = 2 ; i * i <= numkk ; i++){
int cntk = 0;
while(k % i == 0){
k /= i;
cntk++;
if(cntk == 2){
cntk = 0;
ret *= i;
}
}
}
int kkk = gcd(ret , num);
k = numkk / pow(ret , 2);
ret /= kkk;
num /= kkk;
if(k == 0) return ;
if(k == 1){
cout << ret;
if(num != 1){
cout <<"/"<< num;
}
}
else{
if(ret != 1){
cout << ret << "*sqrt(" << k << ")";
if(num != 1)cout << "/" << num;
}
else{
cout << "sqrt(" << k << ")";
if(num != 1)cout << "/" << num;
}
}
}
int main(){
// freopen("uqe.in","r",stdin);
// freopen("uqe.out","w",stdout);
cin >> T >> M;
for(int i = 1 ; i <= T ; i++){
int a , b , c;
cin >> a >> b >> c;
if(!check(a , b , c)){
cout << "NO" << endl;
continue;
}
int numk = ((-1 * b + sqrt(pow(b,2) - 4*a*c)) / 2/a);
if( numk * 2 * a== -1 * b + sqrt(pow(b,2) - 4*a*c) ){
cout << (-1 * b + sqrt(pow(b,2) - 4*a*c)) / 2 / a << endl;
}
else{
int kc = -1 * b / 2 / a;
if(kc != 0) {
if(kc * 2 * a == -1 * b){
cout <<-1 * b / a / 2;
if(!check(a , b , c , -1 * b / a / 2 )) cout << "+";
}
else{
cout <<-1* b << "/" << a * 2 ;
if(!check(a , b , c , -1 * b / a / 2 )) cout << "+";
}
}
else{
if(-1 * b != 0)cout << -1 * b / gcd(abs(-1 * b),2 * a) << "/" << a * 2/ gcd(abs(-1 * b),2 * a);
if(!check(a , b , c , -1 * b / a / 2 )) cout << "+";
}
int k = pow(b,2) - 4*a*c;
print_num(k,2 * a);
cout << endl;
}
}
}
样例都对,提交上去WA了