2019牛客网暑期多校赛第七场B题--Irreducible Polynomial--多项式可分解判别

链接:https://ac.nowcoder.com/acm/contest/887/B
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
In mathematics, a polynomial is an expression consisting of variables (also called indeterminate) and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponents of variables. For example, x2+4x+7x^2 + 4x + 7x2+4x+7.

A polynomial is said to be irreducible if it cannot be factored into two or more non-trivial polynomials with real coefficients.
For example, x2+1x^2+1x2+1 is irreducible, but x2−2x+1x^2-2x+1x2−2x+1 is not (since x2−2x+1=(x−1)(x−1)x^2-2x+1=(x-1)(x-1)x2−2x+1=(x−1)(x−1)).

Given a polynomial of degree with integer coefficients: anxn+an−1xn−1+…+a1x+a0a_nxn+a_{n-1}x{n-1}+…+a_1x+a_0an​xn+an−1​xn−1+…+a1​x+a0​, you need to check whether it is irreducible or not.
输入描述:

The first line of the input gives the number of test cases, T (T≤100)T\ (T \leq 100)T (T≤100). test cases follow.

For each test case, the first line contains one integers n (0≤n≤20)n\ (0 \leq n \leq 20)n (0≤n≤20). Next line contains n + 1n\ +\ 1n + 1 integer numbers:
an,an−1,…,a1,a0a_n, a_{n-1}, …, a_1, a_0an​,an−1​,…,a1​,a0​

−109≤ai≤109-10^9 \leq a_i \leq 10^9−109≤ai​≤109

an≠0a_n \ne 0an​​=0

输出描述:

For each test case, output “Yes” if it is irreducible, otherwise “No”.

示例1
输入

2
2
1 -2 1
2
1 0 1

输出

No
Yes

题意:输入一个n次幂的多项式,如果可以因式分解就输出No,不然输出Yes.

题解:一开始想复杂了,但是发现过题数这么多,后来才知道这在数学上是已经有证明和结论的。

结论如下(n表示多项式最高幂次):(n>2 ) or (n==2&&b^2-4ac>=0)可分解,其他情况不可分解。

AC代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100];
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<=n;i++)
        cin>>a[i];
        if(n>2||(n==2&&(a[1]*a[1]-4*a[0]*a[2]>=0)))
        cout<<"No\n";
        else cout<<"Yes\n";
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值