J T3 TLE 80pts
  • 板块学术版
  • 楼主wangyi_c
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/10/21 21:44
  • 上次更新2023/11/2 12:07:04
查看原帖
J T3 TLE 80pts
560044
wangyi_c楼主2023/10/21 21:44
//finished at 10:54 
//guanzhu luogu 560044 thank you
//ZLQ AK IOI
//The last problem!!!!
//What a terrible large moni problem! shit! 114514
//We've known each other ~ for so long
//You heart is being aching but,you're too shy to say it
//Inside we both know what's being ~ going on
//We know the game and we're ~ gonna play it
//And if ask me what am how I feeling.Don't tell me you're too ~ blind to see
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,M,a,b,c,deta;
int read(){
	int num=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-f;
		ch=getchar();
	}
	while(isdigit(ch)){
		num=(num<<1)+(num<<3)+(ch^'0');
		ch=getchar();
	}
	return num*f;
}
int get_deta(int a,int b,int c){
	return b*b-4ll*a*c;
}
bool check(int x){//in order to judge whether a number can be seprated into a*a or not 
	int l=1,r=x;
	while(l+1<r){
		int mid=(l+r)/2;
		if(mid*mid<x){
			l=mid;
		}
		else r=mid;
	}
	if(l*l==x) return true;
	if(r*r==x) return true;
	return false;
}
void solve1(){
	if(b!=0){
		if(check(deta) || deta==1){//deta is
			int fenzi=(int)sqrt(deta)-b;
			int fenmu=2*a;
			if(fenmu<0){
				fenmu=-fenmu;
				fenzi=-fenzi;
			}
			if(fenzi<0){
				fenzi=-fenzi;
				cout<<"-";
			}
			if(fenzi%fenmu==0){
				cout<<fenzi/fenmu;
			}
			else{
				int zimugcd=__gcd(fenzi,fenmu);
				fenzi/=zimugcd;
				fenmu/=zimugcd;
				cout<<fenzi<<"/"<<fenmu;
			}
			cout<<"\n";
			return ;;
		}
		else{
			int fenzi=-b;
			int fenmu=2*a;
			if(fenmu<0){
				fenmu=-fenmu;
				fenzi=-fenzi;
			}
			if(fenzi<0){
				fenzi=-fenzi;
				cout<<"-";
			}
			if(fenzi%fenmu==0){
				cout<<fenzi/fenmu;
			}
			else{
				int zimugcd=__gcd(fenzi,fenmu);
				fenzi/=zimugcd;
				fenmu/=zimugcd;
				cout<<fenzi<<"/"<<fenmu;
			}
		}
		if(deta==0) return ;
		cout<<"+";
	}
	//the number in front of sqrt
	if(deta==0){
		cout<<0<<"\n";
		return ;
	}
	int tmp=1,t=deta;
	for(int i=2;i<=t;i++){
		while(deta%(i*i)==0){
			tmp*=i;
			deta/=(i*i);
		}
	}
	int fenmu=2*a;
	int zimugcd=__gcd(tmp,2*a);
	tmp/=zimugcd;
	fenmu/=zimugcd;
	if(tmp==1 || tmp==-1){
		if(fenmu<0) fenmu=-fenmu;
		if(fenmu==1){
			if(deta==1){
				cout<<1;
			}
			else cout<<"sqrt("<<deta<<")";
		}
		else{
			if(deta==1){
				cout<<1<<"/"<<fenmu;
			}
			else cout<<"sqrt("<<deta<<")/"<<fenmu;				
		}
		
	}
	else{
		if(tmp<0) tmp=-tmp;
		if(fenmu<0) fenmu=-fenmu;
		if(fenmu==1){
			if(deta==1){
				cout<<tmp;
			}
			else cout<<tmp<<"*sqrt("<<deta<<")";
		}
		else{
			if(deta==1){
				cout<<tmp<<"/"<<fenmu;
			}
			else cout<<tmp<<"*sqrt("<<deta<<")/"<<fenmu;
		}
//			cout<<tmp<<"*sqrt("<<deta<<")/"<<fenmu;
	}
	//ans=-(b/2a) + (sqrt(data)/2a)
	puts("");
}
void solve2(){
	if(b!=0){
		if(check(deta) || deta==1){//deta is
			int fenzi=(int)-sqrt(deta)-b;
			int fenmu=2*a;
			if(fenmu<0){
				fenmu=-fenmu;
				fenzi=-fenzi;
			}
			if(fenzi<0){
				fenzi=-fenzi;
				cout<<"-";
			}
			if(fenzi%fenmu==0){
				cout<<fenzi/fenmu;
			}
			else{
				int zimugcd=__gcd(fenzi,fenmu);
				fenzi/=zimugcd;
				fenmu/=zimugcd;
				cout<<fenzi<<"/"<<fenmu;
			}
			cout<<"\n";
			return ;
		}
		else{
			int fenzi=-b;
			int fenmu=2*a;
			if(fenmu<0){
				fenmu=-fenmu;
				fenzi=-fenzi;
			}
			if(fenzi<0){
				fenzi=-fenzi;
				cout<<"-";
			}
			if(fenzi%fenmu==0){
				cout<<fenzi/fenmu;
			}
			else{
				int zimugcd=__gcd(fenzi,fenmu);
				fenzi/=zimugcd;
				fenmu/=zimugcd;
				cout<<fenzi<<"/"<<fenmu;
			}
		}
		if(deta==0) return ;
		cout<<"+";
	}
	//the number in front of sqrt
	if(deta==0){
		cout<<0<<"\n";
		return ;
	}
	int tmp=1,t=deta;
	for(int i=2;i<=t;i++){
		while(deta%(i*i)==0){
			tmp*=i;
			deta/=(i*i);
		}
	}
	int fenmu=2*a;
	tmp=-tmp;
	int zimugcd=__gcd(tmp,2*a);
	tmp/=zimugcd;
	fenmu/=zimugcd;
	if(tmp==1 || tmp==-1){
		if(fenmu<0) fenmu=-fenmu;
		if(fenmu==1){
			if(deta==1){
				cout<<1;
			}
			else cout<<"sqrt("<<deta<<")";
		}
		else{
			if(deta==1){
				cout<<1<<"/"<<fenmu;
			}
			else cout<<"sqrt("<<deta<<")/"<<fenmu;				
		}
		
	}
	else{
		if(tmp<0) tmp=-tmp;
		if(fenmu<0) fenmu=-fenmu;
		if(fenmu==1){
			if(deta==1){
				cout<<tmp;
			}
			else cout<<tmp<<"*sqrt("<<deta<<")";
		}
		else{
			if(deta==1){
				cout<<tmp<<"/"<<fenmu;
			}
			else cout<<tmp<<"*sqrt("<<deta<<")/"<<fenmu;
		}
//			cout<<tmp<<"*sqrt("<<deta<<")/"<<fenmu;
	}
	//ans=-(b/2a) + (sqrt(data)/2a)
	puts("");
}
signed main(){
//	freopen("uqe.in","r",stdin);
//	freopen("uqe.out","w",stdout);
	T=read(),M=read();
	while(T--){
		a=read(),b=read(),c=read();
		deta=get_deta(a,b,c);
		if(deta<0){
			cout<<"NO\n";
			continue;
		}
		if(1.0*(1.0*sqrt(1.0*deta)-b)/(2.0*a)>1.0*(1.0*(-sqrt(1.0*deta)-b))/(2.0*a)){
			solve1();
		}
		else{
			solve2();
		}
	}
	return 0;
}
/*
1 3213
-2 12 270
*/

RT

2023/10/21 21:44
加载中...