Description
What really impressed Georgie while studying polynomials was the fact that in some cases one can apply different algorithms and techniques developed for integer numbers to polynomials. For example, given two polynomials, one may sum them up, multiply them, or even divide one of them by the other.
The most interesting property of polynomials, at Georgie's point of view, was the fact that a polynomial, just like an integer number, can be factorized. We say that the polynomial is irreducible if it cannot be represented as the product of two or more non-trivial polynomials with real coefficients. Otherwise the polynomial is called reducible. For example, the polynomial x 2 - 2x + 1 is reducible because it can be represented as (x - 1)(x - 1), while the polynomial x 2+ 1 is not. It is well known that any polynomial can be represented as the product of one or more irreducible polynomials.
Given a polynomial with integer coefficients, Georgie would like to know whether it is irreducible. Of course, he would also like to know its factorization, but such problem seems to be too difficult for him now, so he just wants to know about reducibility.
Input
Output
Sample Input
2 1 -2 1
Sample Output
注意:多项式是不能化简的输出 YES,否则输出 NO。
解题思路:若多项式的度大于2肯定能化简,多项式的度小于2,则不能化简。若等于2
则,根据韦达定理判断:b*b-4*a*c>=0;能化简,否则不能。
代码:
#include <iostream>
using namespace std;
int main()
{
int n,a[25];
cin>>n;
for(int i=n;i>=0;i--)
cin>>a[i];
if(n==2)
{
if((a[1]*a[1]-4*a[2]*a[0])>=0)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
if(n<2)
cout<<"YES"<<endl;
if(n>2)
cout<<"NO"<<endl;
return 0;
}