103. Home Computer

Codeforces
IDCF10269103
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Home Computer You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function. The derivative of a "power function" $x^n$ is defined as $n x^(n -1)$. For example, the derivative of $x^5$ would be $5 x^4$. The derivative of a constant multiple of a power function $k x^n$ is defined as $k n x^(n -1)$. For example, the derivative of $3 x^4$ would be $12 x^3$. When taking the derivative of several terms added or subtracted to each other, you take the derivative of each term individually. For example, the derivative of $3 x^5 -5 x^4$ would be $15 x^4 -20 x^3$. The "power rule" described above works intuitively if all terms have at least a degree of two (the number that $x$ is taken to the power of). For terms with a degree of one, such as $7 x$, the derivative is just the constant multiple in front of $x$, which is $7$ for this example. For constant terms (with a degree of zero), the derivative is zero, and can be cancelled out. Using this knowledge, your task is to write a program to determine the derivative of a given polynomial function. The only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant. Output a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function. If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar. ## Input The only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant. ## Output Output a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function. [samples] ## Note If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar.
**Definitions** Let $ P(x) = \sum_{i=1}^{m} c_i x^{d_i} $ be a polynomial, where each term $ c_i x^{d_i} $ is separated by " + " or " - ", with $ c_i \in \mathbb{R} \setminus \{0\} $, $ d_i \in \mathbb{Z}_{\geq 0} $, and $ d_1 > d_2 > \dots > d_m \geq 0 $. The sign of each term is determined by the preceding operator (" + " for positive, " - " for negative). **Constraints** 1. The input is a single line representing $ P(x) $ in standard form with terms separated by " + " or " - ". 2. The first term is non-constant: $ d_1 \geq 1 $. 3. Coefficients $ c_i $ and exponents $ d_i $ are integers. 4. Exponents are non-increasing: $ d_i \geq d_{i+1} $. 5. No term has exponent less than 0. **Objective** Compute the derivative $ P'(x) = \sum_{i=1}^{m} \frac{d}{dx}(c_i x^{d_i}) $. For each term: - If $ d_i = 0 $, derivative is 0 (omit). - If $ d_i = 1 $, derivative is $ c_i $. - If $ d_i \geq 2 $, derivative is $ c_i \cdot d_i \cdot x^{d_i - 1} $. Output $ P'(x) $ as a string with terms separated by " + " or " - ", omitting zero terms, and formatting coefficients and exponents as integers without unnecessary symbols (e.g., no $ x^0 $, no coefficient 1 unless constant).
API Response (JSON)
{
  "problem": {
    "name": "103. Home Computer",
    "description": {
      "content": "Home Computer You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function. ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269103"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Home Computer\n\nYou are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function.\n\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ P(x) = \\sum_{i=1}^{m} c_i x^{d_i} $ be a polynomial, where each term $ c_i x^{d_i} $ is separated by \" + \" or \" - \", with $ c_i \\in \\mathbb{R} \\setminus \\{0\\} $, $ d_i \\in \\mat...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments