博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2019牛客网暑期多校赛第七场B题--Irreducible Polynomial--多项式可分解判别
阅读量:736 次
发布时间:2019-03-21

本文共 1775 字,大约阅读时间需要 5 分钟。

链接:

来源:牛客网

时间限制: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

输入

221 -2 121 0 1

输出

NoYes

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

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

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

AC代码

#include
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;}

转载地址:http://zyvgz.baihongyu.com/

你可能感兴趣的文章