#P4598. [HEOI2012] Akai 的数学作业

[HEOI2012] Akai 的数学作业

Description

On the blackboard remains a piece of math homework Akai once did. It is actually not a very difficult problem:

"Given a univariate polynomial equation of degree nn:

a0+a1x+a2x2++anxn=0a_0 + a_1 x + a_2 x^2 + \cdots + a_n x^n = 0

Find all rational solutions of this equation."

Akai still vividly remembers the nights he stayed up solving it. He even remembers how much scrap paper he wasted. But he just can’t recall the final answers. Can you help him?

Input Format

The first line contains an integer nn. The second line contains n+1n + 1 integers, representing a0a_0 to ana_n.

Output Format

Output an integer tt on the first line, the number of rational solutions. Then output tt lines, each containing one solution. Each solution must be printed as a fraction in lowest terms, with a positive denominator. If a solution is an integer, output the integer directly. Equivalent solutions should be output only once. Output all solutions in increasing order.

3
-24 14 29 6 
3
-4
-3/2
2/3 

Hint

  • For 30% of the testdata, n10n \leq 10.
  • For 100% of the testdata, n100n \leq 100, ai1.3×108|a_i| \leq 1.3 \times 10^8, an0a_n \ne 0.

HEOI 2012 Day 1 Task 1.

Translated by ChatGPT 5