Codeforces Round 462 (Div. 1)
B
A Determined Cleanup
Codeforces
2000
原题
← AC →
翻译中…

In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.

翻译中…

Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...

翻译中…

Given two integers $*p*$ and $*k*$, find a polynomial $*f*(*x*)$ with non-negative integer coefficients strictly less than $*k*$, whose remainder is $*p*$ when divided by $(*x* + *k*)$. That is, $*f*(*x*) = *q*(*x*)·(*x* + *k*) + *p*$, where $*q*(*x*)$ is a polynomial (not necessarily with integer coefficients).

翻译中…

Input

翻译中…

The only line of input contains two space-separated integers $*p*$ and $*k*$ ($1 ≤ *p* ≤ 10^{18}$, $2 ≤ *k* ≤ 2 000$).

翻译中…

Output

翻译中…

If the polynomial does not exist, print a single integer -1, or output two lines otherwise.

翻译中…

In the first line print a non-negative integer $*d*$ — the number of coefficients in the polynomial.

翻译中…

In the second line print $*d*$ space-separated integers $*a*_{0}, *a*_{1}, ..., *a*_{*d* - 1}$, describing a polynomial image fulfilling the given requirements. Your output should satisfy $0 ≤ *a*_{*i*} < *k*$ for all $0 ≤ *i* ≤ *d* - 1$, and $*a*_{*d* - 1} ≠ 0$.

翻译中…

If there are many possible solutions, print any of them.

翻译中…

Note

翻译中…

In the first example, $*f*(*x*) = *x*^{6} + *x*^{5} + *x*^{4} + *x* = (*x*^{5} - *x*^{4} + 3*x*^{3} - 6*x*^{2} + 12*x* - 23)·(*x* + 2) + 46$.

翻译中…

In the second example, $*f*(*x*) = *x*^{2} + 205*x* + 92 = (*x* - 9)·(*x* + 214) + 2018$.

翻译中…

样例

Input #1
46 2
Output #1
7
0 1 0 0 1 1 1
InputCopy OutputCopy
Input #2
2018 214
Output #2
3
92 205 1
InputCopy OutputCopy
题目信息
题号
933B
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。