B Irreducible Polynomial
Problem
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 .
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+1 is irreducible, but x2-2x+1 is not (since x^2-2x+1=(x-1)(x-1)).
Given a polynomial of degree with integer coefficients: anxn+an-1xn-1+…+a1x+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 test cases follow.
For each test case, the first line contains one integers n (0≤n≤20). Next line contains n + 1 integer numbers:
an, an-1, …, a1, a0
-109 < = ai <= 109
输出描述:
For each test case, output “Yes” if it is irreducible, otherwise “No”.
示例1
输入
2
2
1 -2 1
2
1 0 1
输出
No
Yes
题意
判断一个多项式在实数范围内能否被因式分解
分析
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int a[25];
int n;
scanf("%d",&n);
for(int i=0;i<n+1;i++) scanf("%d",&a[i]);
if(n>2) cout<<"No"<<endl;
else if(n==1) cout<<"Yes"<<endl;
else {
int k=a[1]*a[1]-4*a[0]*a[2];
if(k<0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
return 0;
}