//90分,不想改了,用求根公式求两根即可 #include <iostream> #include <cstdio> #include <cmath> using namespace std; unsigned long long a[3]; string edit(int x) { string num=""; if (x==0) return "x"; int t=abs(x); while (t) { num+=t%10+'0'; t/=10; } for (int i=0;i<num.size()/2;++i) swap(num[i],num[num.size()-i-1]); if (x>0) return "(x+"+num+")"; else return "(x-"+num+")"; return 0; } int main() { //freopen("in.txt","r",stdin); a[2]=1; int x; char c; while ((c=getchar())!=EOF) { if (c!='+' && c!='-') continue; int t; cin>>t; //cout<<'!'; if (getchar()==EOF) { a[0]=t; if (c=='-') a[0]*=-1; break; } else { if (t==0) a[1]=1; else a[1]=t; if (c=='-') a[1]*=-1; } } //cout<<a[1]<<' '<<a[0]<<endl; int delta=sqrt(a[1]*a[1]-4*a[0]); int x2=(-a[1]+delta)/-2,x1=(-a[1]-delta)/-2; //cout<<delta<<' '<<x1<<' '<<x2<<endl; string s1=edit(x1),s2=edit(x2); if (s1==s2) cout<<s1<<"^2"; else cout<<s1<<s2; return 0; }
5
2
2015
2
2015