记录编号 583978 评测结果 AAAAAAAAAA
题目名称 [CSP 2023J]一元二次方程 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.006 s
提交时间 2023-10-25 20:05:01 内存使用 1.72 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int n,m;
int a,b,c;
int gcd(int x,int y){
    if(y == 0)return x;
    x = abs(x),y = abs(y);
    return gcd(y,x%y);
}
int main(){
    freopen("uqe.in","r",stdin);
    freopen("uqe.out","w",stdout);
    scanf("%d%d",&n,&m);
    while(n--){
        scanf("%d%d%d",&a,&b,&c);
        int sq = b*b-4*a*c,t = 0;
        if(sq < 0)printf("NO\n");
        else{
            if(a < 0)b = -b,a = -a;
            for(int i = 1;i * i <= sq;i++)
                if(sq % (i * i) == 0)t = i;
            if(t * t == sq || sq == 0){
                t -= b;
                if(t % (2*a) == 0)printf("%d\n",t/(2*a));
                else{
                    int gc = gcd(t,2*a);
                    printf("%d/%d\n",t/gc,2*a/gc);
                }
            }
            else{
                sq /= (t * t);
                if(-b != 0){
                    if((-b) % (2*a) == 0)printf("%d+",(-b)/(2*a));
                    else{
                        int gc = gcd(-b,2*a);
                        printf("%d/%d+",(-b)/gc,(2*a)/gc);
                    }
                }
                if(t % (2*a) == 0){
                    if(t/(2*a) != 1)printf("%d*",t/(2*a));
                    printf("sqrt(%d)\n",sq);
                }
                else{
                    int gc = gcd(t,2*a);
                    if(t/gc != 1)printf("%d*",t/gc);
                    printf("sqrt(%d)/%d\n",sq,2*a/gc);
                }
            }
        }
    }
    
    return 0;
    
}