求助
#include<bits/stdc++.h>
using namespace std;
long long T,M,a,b,c;
long long ck(long long r){
long long res=0;
for(int i=2;i<=sqrt(r);i++){
if(r%i==0){
long long tmp=r,cnt=0,po=1;
while(tmp%i==0){
po*=i;
cnt++;
tmp/=i;
}
if(cnt>1){
if(cnt&1){
res*=sqrt(po/i);
r/=po/i;
}else{
res*=sqrt(po);
r/=po;
}
}
}
}
return r;
}
long long gcd(long long x,long long y){
if(y==0) return x;
return gcd(y,x%y);
}
void qout(long long x,long long y){
long long z=gcd(x,y);
if(x*y<0) putchar('-');
x/=z,y/=z;
if(y!=1) printf("%lld/%lld",abs(x),abs(y));
else printf("%lld",abs(x));
}
void nout(long long p,long long q,long long r){
long long res=1;
if(p*q<0) putchar('-');
long long gr=ck(r);
p*=sqrt(r/gr);
r=gr;
long long z=gcd(abs(p),abs(q));
p/=z,q/=z;
if(q==1&&p!=1) printf("%lld*sqrt(%lld)",abs(p),r);
else if(p==1&&q!=1) printf("sqrt(%lld)/%lld",r,abs(q));
else if(p==1&&q==1) printf("sqrt(%lld)",r);
else printf("%lld*sqrt(%lld)/%lld",abs(p),r,abs(q));
}
void rout(long long x,long long y,long long p,long long q,long long r){
long long gr=ck(r);
if(gr==1){
x=x*q+(p*sqrt(r))*y;
y*=q;
p=0;
q=0;
r=0;
}
if(x!=0){
qout(x,y);
if(r!=0&&p!=0&&p*q>0){
putchar('+');
}
}
if(r!=0&&p!=0){
nout(p,q,r);
}
puts("");
}
int main(){
freopen("uqe.in","r",stdin);
freopen("uqe.out","w",stdout);
scanf("%lld%lld",&T,&M);
while(T--){
scanf("%lld%lld%lld",&a,&b,&c);
if(b==0){
if(a*c>0) puts("NO");
else{
rout(0,1,1,a,-a*c);
}
continue;
}
if(c==0){
if(b>=0) puts("0");
else rout(-b,a,0,0,0);
continue;
}
long long d=b*b-4*a*c;
if(d<0){
puts("NO");
continue;
}
if(a>0) rout(-b,2*a,1,2*a,d);
if(a<0) rout(-b,2*a,-1,2*a,d);
}
return 0;
}
为啥呢?