#P5248. Construct a Polynomial

    ID: 18484 Type: Default 1000ms 256MiB

Construct a Polynomial

Construct a Polynomial

We are given a non‐negative integer m and the value f(m) of a polynomial f(x) at x = m. The polynomial is defined as follows:

$$ f(x)=a_0+a_1x+a_2x^2+\cdots+a_{n-1}x^{n-1}, \quad (1 \le n \le 100), $$

where each coefficient satisfies

0ai<m,0 \le a_i < m,

and the highest coefficient (i.e. (a_{n-1})) is nonzero. Your task is to construct such a polynomial whose value at x=m is exactly the given number f(m). Note that this is equivalent to expressing f(m) in base m.

</p>

The output should first contain the number of terms n, followed by the n coefficients in order from a0 to an-1 (i.e. in increasing order of power). It is guaranteed that a valid solution exists and that the number of terms does not exceed 100.

inputFormat

The input consists of two integers on one or two lines:

  • m (the base, an integer > 0)
  • f(m) (a non-negative integer whose base-m representation has at most 100 digits and is non-zero if there is more than 1 digit)

outputFormat

Output the number of terms n (i.e. the number of coefficients) on the first line, and on the second line output n space-separated integers representing a0, a1, \ldots, an-1.

sample

10 123
3

3 2 1

</p>