Factoring a Polynomial(多项式分解-水题)

 
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 2920   Accepted: 1483

Description

Recently Georgie has learned about polynomials. A polynomial in one variable can be viewed as a formal sum anxn + an-1xn-1 + . . . + a1x + a0 , where x is the formal variable and a i are the coefficients of the polynomial. The greatest i such that ai != 0 is called the degree of the polynomial. If ai = 0 for all i, the degree of the polynomial is considered to be -∞. If the degree of the polynomial is zero or -∞, it is called trivial, otherwise it is called non-trivial.
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 x2 - 2x + 1 is reducible because it can be represented as (x - 1)(x - 1), while the polynomial x2 + 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

The first line of the input contains n --- the degree of the polynomial (0 <= n <= 20). Next line contains n + 1 integer numbers, an , an-1 , . . . , a1 , a0 --- polynomial coefficients (-1000 <= ai <= 1000, an != 0).

Output

Output YES if the polynomial given in the input file is irreducible and NO in the other case.

Sample Input

2 
1 -2 1 

Sample Output

NO


题意:给出一个实系数多项式,问是否可以分解。

思路:转载于https://blog.csdn.net/weixin_34043301/article/details/86285273

实系数多项式因式分解定理  每个次数大于零的实系数多项式都可以在实数域上唯一地分解成一些一次或二次不可约因式的乘积。

所以对于大于2的情况一定可以分解。对于<=2的情况,判断其本身是否可约,一次一定不可约,二次用b^2-4ac判断是否有根,有则可约,否则不可约。

代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    if (n <= 1){
        printf("YES\n");
        return 0;
    }
    if (n > 2){
        printf("NO\n");
        return 0;
    }
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (b * b - 4 * a * c >= 0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

 

posted @ 2020-04-21 16:46  AlexLIN·  阅读(292)  评论(0)    收藏  举报