luogu#P5248. [LnOI2019SP] 快速多项式变换(FPT)

[LnOI2019SP] 快速多项式变换(FPT)

Background

avartar

Problem Description

This is a constructive problem.

Shino thinks of a polynomial f(x)f(x) with n+1n+1 terms. The degree of the ii-th term is ii, and its coefficient is aia_i:

f(x)=a0+a1x+a2x2+a3x3++anxnf(x)=a_0+a_1x+a_2x^2+a_3x^3+ \cdots +a_nx^n

Given mm and the value of f(m)f(m) (that is, the value of this polynomial when x=mx=m), please construct a polynomial such that for any 0ai<m0 \leq a_i < m, aia_i is a non-negative integer.

Let the number of terms of the polynomial you construct be nn. Then it must satisfy 1n1001 \le n \le 100, and the leading coefficient must be non-zero.

Input Format

Two integers, mm and f(m)f(m).

Output Format

The first line outputs a positive integer nn, which represents the number of terms of the polynomial.

The second line outputs nn non-negative integers (a0a_0 to an1a_{n-1}) in order, with exactly one space between each pair of adjacent integers.

10 10
2
0 1

Hint

For 20%20\% of the testdata, 2m52 \le m \le 5.

For 100%100\% of the testdata, 2m,f(m)10182 \le m,f(m) \le 10^{18}.

For all testdata, the time limit is 1000ms1000\text{ms} and the memory limit is 256MB256\text{MB}. You may enable O2 optimization.

Translated by ChatGPT 5