90pts 求hack
查看原帖
90pts 求hack
1020096
LiHR_210222楼主2023/11/26 10:29

#4一直不对 测了好几遍 跪求大佬hack qwq

#include <bits/stdc++.h>
using namespace std;

int t,m,a,b,c,dt,ans;

int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
void turnR(int x,int y){
	 if(x==0){
		cout<<'0';
	}
	else{
		int d=gcd(abs(x),abs(y));
		if(y/d==1)cout<<x/d;
		else if(y/d==-1)cout<<-x/d;
		else if(x*y>0)cout<<abs(x/d)<<'/'<<abs(y/d);
		else cout<<'-'<<abs(x/d)<<'/'<<abs(y/d);
	}
	return;
}

void turnSQ(int x){
	double q2=1;
	for(int i=2;i*i<=x;i++){
		while(x%(i*i)==0){
			q2*=i;
			x/=i*i;
		}
	}
	q2/=abs(2*a);
	if(q2==1)
		cout<<"sqrt("<<x<<')';
	else if(int(q2)==q2)
		cout<<q2<<'*'<<"sqrt("<<x<<')';
	else if(int(1/q2)==1/q2)
		cout<<"sqrt("<<x<<")/"<<(1/q2);
	else{
		q2*=abs(2*a);
		cout<<q2/gcd(q2,2*a)<<"*sqrt("<<x<<")/"<<2*a/gcd(q2,2*a);
	}
	return;
}

int main(){
//	freopen("uqe2.in","r",stdin);
//	freopen("uqe.out","w",stdout);
    cin>>t>>m;
    while(t--){
        cin>>a>>b>>c;
        if(a<0){
			a=-a;b=-b;c=-c;
		}
        dt=b*b-4*a*c;
        if(dt<0)
			cout<<"NO";
        if(dt==0)
        	turnR(-b,2*a);
        if(dt>0){
        	if(a>0){
			if(int((-b+sqrt(dt))/(2*a))==(-b+sqrt(dt))/(2*a)){
				cout<<(-b+sqrt(dt))/(2*a);
				}
				else if(int(sqrt(dt))==sqrt(dt))
				turnR(-b+sqrt(dt),2*a);
			else{
				if(b==0){
					turnSQ(dt);
				}
				else{
					turnR(-b,2*a);
					cout<<'+';
					turnSQ(dt);	
				}
				}
			}
        }
		if(t!=0)
		cout<<endl;
	}
    return 0;
}
2023/11/26 10:29
加载中...