Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,503 Bytes
ab396f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<p>
Consider an N-degree polynomial, expressed as follows:
</p>

<p>
  <b>P</b><sub>N</sub> * x<sup>N</sup> + <b>P</b><sub>N-1</sub> * x<sup>N-1</sup> + ... + <b>P</b><sub>1</sub> * x<sup>1</sup> + <b>P</b><sub>0</sub> * x<sup>0</sup>
</p>

<p>
You'd like to find all of the polynomial's x-intercepts &mdash; in other words, all distinct real values of x for which the expression evaluates to 0.
</p>

<p>
Unfortunately, the order of operations has been reversed: 
Addition (<strong>+</strong>) now has the highest precedence, followed by multiplication (<strong>*</strong>), followed by exponentiation (<strong>^</strong>). 
In other words, an expression like a<sup>b</sup> + c * d should be evaluated as a<sup>((b+c)*d)</sup>. 
For our purposes, exponentiation is right-associative (in other words, a<sup>b<sup>c</sup></sup> = a<sup>(b<sup>c</sup>)</sup>), 
and 0<sup>0</sup> = 1.
The unary negation operator still has the highest precedence, so the expression -2<sup>-3</sup> * -1 + -2 evaluates to -2<sup>(-3 * (-1 + -2))</sup> = -2<sup>9</sup> = -512.
</p>

<h3>Input</h3>

<p>
Input begins with an integer <strong>T</strong>, the number of polynomials.
For each polynomial, there is first a line containing the integer <strong>N</strong>, the degree of the polynomial.
Then, <strong>N</strong>+1 lines follow. The <em>i</em>th of these lines contains the integer <strong>P<sub>i-1</sub></strong>.
</p>

<h3>Output</h3>

<p>
For the <em>i</em>th polynomial, print a line containing "Case #<em>i</em>: <strong>K</strong>", 
where <strong>K</strong> is the number of distinct real values of <strong>x</strong> for which the polynomial evaluates to 0.
Then print <strong>K</strong> lines, each containing such a value of <strong>x</strong>, in increasing order.
</p>

<p>
Absolute and relative errors of up to 10<sup>-6</sup> will be ignored in the x-intercepts you output. However, <strong>K</strong> must be exactly correct.
</p>


<h3>Constraints</h3>

<p>
1 &le; <strong>T</strong> &le; 200 <br />
0 &le; <strong>N</strong> &le; 50 <br />
-50 &le; <strong>P<sub>i</sub></strong> &le; 50 <br />
<strong>P<sub>N</sub></strong> &ne; 0 <br />
</p>


<h3>Explanation of Sample</h3>

<p>
In the first case, the polynomial is 1 * x<sup>1</sup> + 1 * x<sup>0</sup>. With the order of operations reversed, this is evaluated as (1 * x)<sup>(((1 + 1) * x)<sup>0</sup>)</sup>, which is equal to 0 only when x = 0.
</p>

<p>
In the second case, the polynomial does not evaluate to 0 for any real value x.
</p>