POJ 2126 Factoring a Polynomial

本文探讨了多项式的可分解性概念,通过实例说明如何判断一个多项式是否可被分解为非平凡多项式的乘积,并提供了针对不同情况的判断方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Factoring a Polynomial
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2412 Accepted: 1256

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


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s[30],i;

    if(n!=2)
    {
        for(i=0;i<n;i++)
        cin>>s[i];
        if(n<2)
        cout<<"YES"<<endl;
        if(n>2)
        cout<<"NO"<<endl;
    }
    if(n==2)
    {
        int a,b,c;
        cin>>a>>b>>c;
        double y;
        y=b*b-4*a*c;
        if(y>=0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}


很简单的题 ,如果度大于2,一定能被分解,小于2一定不能被分解,等于2时,判断b*b-4*a*c是否大于0,大于0则可被分解。

这道题注意的是,不可化简得输出YES,可化简的输出NO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值