Irreducible Polynomial
题目描述
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 + 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+1 is irreducible, but x2-2x+1 is not (since x2-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). 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
an≠0输出
For each test case, output “Yes” if it is irreducible, otherwise “No”.
样例输入
2 2 1 -2 1 2 1 0 1
样例输出
No Yes
小知识点:
n表示最高次幂,当n>=3时,都可约,当n==2时,判断b^2-4ac,若大于0,可约,否则不可约,n<2时,肯定都不能约
代码:
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int N=200010;
int T;
int main()
{//注意不可约输出Yes cin>>T;while(T--){int n,a[110],f=0;cin>>n;for(int i=1;i<=n+1;i++) cin>>a[i];if(n>2) f=1;if(n==2){if(a[2]*a[2]-4*a[1]*a[3]>=0) f=1;}if(f==0) cout<<"Yes\n";else cout<<"No\n";}return 0;
}