#P16785. [蓝桥杯 2026 国 A] 多项式积分

    ID: 19126 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>模拟字符串微积分2026蓝桥杯国赛

[蓝桥杯 2026 国 A] 多项式积分

Problem Description

Xiao Lan is learning calculus. Today, his homework is to find an indefinite integral of a polynomial in xx. Please help him complete this task.

Given a polynomial in xx, output one possible result of its indefinite integral. The constant of integration does not need to be output.

Input Format

Input one line containing a polynomial in xx.

The polynomial consists of several terms with integer coefficients, and each term has a non-negative integer exponent. In particular, a term with exponent 00 represents a constant term.

The input polynomial satisfies the following rules:

  • Terms are given in descending order of exponents.
  • If the first term is negative, it may start with a minus sign; if the first term is positive, there is no leading ++.
  • Except for the first term, the remaining terms are separated by ++ or -, and the sign belongs to the corresponding term.
  • A term with exponent 00 is written directly as an integer constant.
  • A term with exponent 11 is written as cx\text{cx} or x\text{x}; when the coefficient is 11 or 1-1, the digit 11 may be omitted.
  • A term with exponent greater than 11 is written as cxk\text{cx}^{\wedge}\text{k} or xk\text{x}^{\wedge}\text{k}, where k>1k > 1; when the coefficient is 11 or 1-1, the digit 11 may be omitted.
  • The coefficient of every term is non-zero; there are no redundant terms with coefficient 00.

Output Format

Output one line representing the indefinite integral of the input polynomial.

You do not need to write the constant of integration. The terms in the result should be arranged in descending order of exponents.

When outputting the polynomial, the following formatting rules must be followed:

  • If the leading term’s coefficient is positive, do not output a leading ++.
  • For non-leading terms: if the coefficient is positive, output a leading ++; if the coefficient is negative, output a leading -.
  • When the exponent is 11, output x\text{x}, not x1\text{x}^{\wedge}1.
  • When a term’s coefficient is 11 or 1-1, omit the digit 11, keeping only the sign and the letter part.
  • If a term’s coefficient is a fraction pq\frac{p}{q}, output it as p/q\text{p}/\text{q}, where pp and qq are coprime and q>0q > 0.
  • If the fractional coefficient is negative, the minus sign should be placed in the numerator.
  • If the denominator becomes 11 after simplification, output it as an integer, not as a fraction.
  • The output must not contain redundant terms with coefficient 00.
4x^5-4x^3+2
2/3x^6-x^4+2x
-100x^100+105x^2

-100/101x^101+35x^3
7
7x
x-1
1/2x^2-x

Hint

Sample Explanation

For sample 11:

$$\int (4x^5 - 4x^3 + 2) \, dx = \frac{2}{3} x^6 - x^4 + 2x + C.$$

The constant of integration CC does not need to be output, so output 2/3x6-x4+2x\text{2/3x}^\wedge\text{6-x}^\wedge\text{4+2x}.

For sample 22:

$$\int (-100x^{100} + 105x^2) \, dx = -\frac{100}{101} x^{101} + 35x^3 + C.$$

So output $\text{-100/101x}^\wedge\text{101+35x}^\wedge\text{3}$.

For sample 33, the input polynomial is the constant 77, and the integral result is 7x+C7x + C, so output 7x\text{7x}.

For sample 44:

(x1)dx=12x2x+C.\int (x - 1) \, dx = \frac{1}{2} x^2 - x + C.

So output 1/2x2-x\text{1/2x}^\wedge\text{2-x}.

Constraints and Notes for Test Cases

For 50%50\% of the testdata, it is guaranteed that every term’s coefficient in the integral result is a positive integer.

For all testdata, it is guaranteed that:

  • The number of terms in the input polynomial does not exceed 1000010000.
  • The exponent of each term does not exceed 10810^8.
  • The absolute value of each coefficient does not exceed 10810^8.
  • The terms in the input polynomial are given in descending order of exponents.

Translated by ChatGPT 5