2019牛客多校 第七场 B Irreducible Polynomial 多项式因式分解判断

链接: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_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

题解:实数域上,不可拆分只有两种:一次多项式和二次多项式(△  <  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;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值