#P16785. [蓝桥杯 2026 国 A] 多项式积分
[蓝桥杯 2026 国 A] 多项式积分
Problem Description
Xiao Lan is learning calculus. Today, his homework is to find an indefinite integral of a polynomial in . Please help him complete this task.
Given a polynomial in , 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 .
The polynomial consists of several terms with integer coefficients, and each term has a non-negative integer exponent. In particular, a term with exponent 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 is written directly as an integer constant.
- A term with exponent is written as or ; when the coefficient is or , the digit may be omitted.
- A term with exponent greater than is written as or , where ; when the coefficient is or , the digit may be omitted.
- The coefficient of every term is non-zero; there are no redundant terms with coefficient .
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 , output , not .
- When a term’s coefficient is or , omit the digit , keeping only the sign and the letter part.
- If a term’s coefficient is a fraction , output it as , where and are coprime and .
- If the fractional coefficient is negative, the minus sign should be placed in the numerator.
- If the denominator becomes after simplification, output it as an integer, not as a fraction.
- The output must not contain redundant terms with coefficient .
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 :
$$\int (4x^5 - 4x^3 + 2) \, dx = \frac{2}{3} x^6 - x^4 + 2x + C.$$The constant of integration does not need to be output, so output .
For sample :
$$\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 , the input polynomial is the constant , and the integral result is , so output .
For sample :
So output .
Constraints and Notes for Test Cases
For 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 .
- The exponent of each term does not exceed .
- The absolute value of each coefficient does not exceed .
- The terms in the input polynomial are given in descending order of exponents.
Translated by ChatGPT 5