F. Polynom

Codeforces
IDCF100F
Time2000ms
Memory64MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
You are given a polynom in form _p_(_x_) = (_x_ + _a_1)·(_x_ + _a_2)·... (_x_ + _a__n_). Write Pike program to print it in a standard form _p_(_x_) = _x__n_ + _b_1_x__n_ - 1 + ... + _b__n_ - 1_x_ + _b__n_. You should write each addend in form «_C*X^K_» (for example, _5*X^8_). Please, write the polynom in the shortest way, so you should skip unnecessary terms: some terms «_C*X^K_» should be reduced or even omitted. Look for the samples for clarification. ## Input The first line of the input contains _n_ (1 ≤ _n_ ≤ 9). The following _n_ lines contain integer _a__i_ ( - 10 ≤ _a__i_ ≤ 10). ## Output Print the given polynom in a standard way. Note, that the answer in this problem response uniquely determined. [samples]
给定一个多项式,形式为 $p(x) = (x + a1)·(x + a2)·... (x + an)$。请编写一个 Pike 程序,将其以标准形式 $p(x) = x^n + b1x^{n - 1} + ... + bn - 1x + bn$ 输出。每个项应写成 «_C*X^K_» 的形式(例如,_5*X^8_)。 请以最简形式写出该多项式,因此应省略不必要的项:某些 «_C*X^K_» 项应被化简甚至省略。请参考样例以获得更清晰的说明。 输入的第一行包含 #cf_span[n](#cf_span[1 ≤ n ≤ 9])。接下来的 #cf_span[n] 行每行包含一个整数 #cf_span[ai](#cf_span[ - 10 ≤ ai ≤ 10])。 请以标准形式输出该多项式。注意,本题的答案是唯一确定的。 ## Input 输入的第一行包含 #cf_span[n](#cf_span[1 ≤ n ≤ 9])。接下来的 #cf_span[n] 行每行包含一个整数 #cf_span[ai](#cf_span[ - 10 ≤ ai ≤ 10])。 ## Output 请以标准形式输出该多项式。注意,本题的答案是唯一确定的。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ with $ 1 \leq n \leq 9 $. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of integers with $ -10 \leq a_i \leq 10 $. Define the polynomial: $$ p(x) = \prod_{i=1}^n (x + a_i) $$ **Objective** Expand $ p(x) $ into the standard form: $$ p(x) = x^n + b_1 x^{n-1} + b_2 x^{n-2} + \cdots + b_{n-1} x + b_n $$ and output each non-zero term $ b_k x^{n-k} $ (for $ k = 0, \dots, n $, where $ b_0 = 1 $) in the format: - $ \texttt{C*X^K} $ if $ |C| > 1 $ or $ K = 0 $, - $ \texttt{X^K} $ if $ C = 1 $ and $ K > 0 $, - $ \texttt{-X^K} $ if $ C = -1 $ and $ K > 0 $, - $ \texttt{C} $ if $ K = 0 $ and $ |C| > 1 $, - $ \texttt{1} $ or $ \texttt{-1} $ if $ K = 0 $ and $ C = \pm 1 $, - omit terms with $ b_k = 0 $. Terms must be printed in descending order of degree, with no leading `+` for the first term.
Samples
Input #1
2
-1
1
Output #1
X^2-1
Input #2
2
1
1
Output #2
X^2+2*X+1
API Response (JSON)
{
  "problem": {
    "name": "F. Polynom",
    "description": {
      "content": "You are given a polynom in form _p_(_x_) = (_x_ + _a_1)·(_x_ + _a_2)·... (_x_ + _a__n_). Write Pike program to print it in a standard form _p_(_x_) = _x__n_ + _b_1_x__n_ - 1 + ... + _b__n_ - 1_x_ + _b",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF100F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a polynom in form _p_(_x_) = (_x_ + _a_1)·(_x_ + _a_2)·... (_x_ + _a__n_). Write Pike program to print it in a standard form _p_(_x_) = _x__n_ + _b_1_x__n_ - 1 + ... + _b__n_ - 1_x_ + _b...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定一个多项式,形式为 $p(x) = (x + a1)·(x + a2)·... (x + an)$。请编写一个 Pike 程序,将其以标准形式 $p(x) = x^n + b1x^{n - 1} + ... + bn - 1x + bn$ 输出。每个项应写成 «_C*X^K_» 的形式(例如,_5*X^8_)。\n\n请以最简形式写出该多项式,因此应省略不必要的项:某些 «_C*X^K_» 项应被...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ with $ 1 \\leq n \\leq 9 $.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of integers with $ -10 \\leq a_i \\leq 10 $.  \nDefine the polynomial:  \n$$ p(x) = ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments