编程介的小学生 2017-02-24 06:07 采纳率: 20.5%
浏览 1215
已采纳

Integer Roots of a Polynomial

A polynomial of degree n has the common form as
p(x) = a[n]*x^n + a[n-1]*x^(n-1) + ... + a[1]*x + a[0].
In general it is difficult to find the roots of a polynomial of degree 3 or higher, unless you have a powerful computer program available. The following observation might be helpful:
Let p(x) be a polynomial with integer coefficients. If p(c) = 0 for some integer c, then (x - c) is a factor of p(x) and c is a divisor of the constant term of p(x).

Your task is to write a program to find all the integer roots of a given polynomial with integer coefficients.

Input

The first line of input contains a positive integer N (N <= 100), then followed by N test cases. Each test case consists of 2 lines of integers: the first line contains a non-negative integer n (n <= 20) which is the degree of the polynomial; and the second line contains n+1 integers a[n], a[n-1], ..., a[1], and a[0]. Note that 0-polynomial will not appear in the input.

Output

For each test case, print in one line all the integer roots of the given polynomial in ascending order. The roots must be separated by one space. If there is no integer root at all, just print "NIR" (means No Integer Root).

Sample Input

3
3
-1 18 -96 160
2
1 0 1
2
2 3 0

Sample Output

4 4 10
NIR
0

  • 写回答

2条回答

  • shen_wei 2017-02-24 07:22
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?