链接:https://ac.nowcoder.com/acm/contest/887/B
来源:牛客网
Irreducible Polynomial
时间限制: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_nx^n+a_{n-1}x^{n-1}+...+a_1x+a_0anxn+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\ (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
题解:实数域上,不可拆分只有两种:一次多项式和二次多项式(△ < 0)。
注意这个输出是反着的。
#include<iostream>
#include<cstdio>
using namespace std;
int t,n;
long long a[25],del;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=n;i>=0;--i)scanf("%lld",&a[i]);
if(n==0||n==1)printf("Yes\n");
else if(n>2)printf("No\n");
else{
if(a[1]*a[1]-4*a[0]*a[2]<0)printf("Yes\n");
else printf("No\n");
}
}
return 0;
}