编程介的小学生 2017-05-02 15:42 采纳率: 20.5%
浏览 859
已采纳

Factoring a Polynomial

Recently Georgie has learned about polynomials. A polynomial in one variable can be viewed as a formal sum anx^n+an-1x^n-1+...+a1x+a0, where x is the formal variable and ai are the coefficients of the polynomial. The greatest i such that ai != 0 is called the degree of the polynomial. If ai = 0 for all i, the degree of the polynomial is considered to be -inf. If the degree of the polynomial is zero or -inf, it is called trivial, otherwise it is called non-trivial.
What really impressed Georgie while studying polynomials was the fact that in some cases one can apply different algorithms and techniques developed for integer numbers to polynomials. For example, given two polynomials, one may sum them up, multiply them, or even divide one of them by the other.

The most interesting property of polynomials, at Georgie's point of view, was the fact that a polynomial, just like an integer number, can be factorized. We say that the polynomial is irreducible if it cannot be represented as the product of two or more non-trivial polynomials with real coefficients. Otherwise the polynomial is called reducible. For example, the polynomial x^2-2x+1 is reducible because it can be represented as (x - 1) (x - 1), while the polynomial x^2+1 is not. It is well known that any polynomial can be represented as the product of one or more irreducible polynomials.

Given a polynomial with integer coefficients, Georgie would like to know whether it is irreducible. Of course, he would also like to know its factorization, but such problem seems to be too difficult for him now, so he just wants to know about reducibility.

Input

The first line of the input contains n - the degree of the polynomial (0 <= n <= 20). Next line contains n + 1 integer numbers, an, an-1, ..., a1, a0 - polynomial coefficients (-1000 <= ai <= 1000, an != 0).

Output

Output "YES" if the polynomial given in the input is irreducible and "NO" in the other case.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

2

2
1 -2 1

2
1 0 1

Sample Output

NO

YES

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-05-03 15:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大