{"raw_statement":[{"iden":"statement","content":"_In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must._\n\nLittle Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...\n\nGiven 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)."},{"iden":"input","content":"The only line of input contains two space-separated integers _p_ and _k_ (1 ≤ _p_ ≤ 1018, 2 ≤ _k_ ≤ 2 000)."},{"iden":"output","content":"If the polynomial does not exist, print a single integer _\\-1_, or output two lines otherwise.\n\nIn the first line print a non-negative integer _d_ — the number of coefficients in the polynomial.\n\nIn the second line print _d_ space-separated integers _a_0, _a_1, ..., _a__d_ - 1, describing a polynomial fulfilling the given requirements. Your output should satisfy 0 ≤ _a__i_ < _k_ for all 0 ≤ _i_ ≤ _d_ - 1, and _a__d_ - 1 ≠ 0.\n\nIf there are many possible solutions, print any of them."},{"iden":"examples","content":"Input\n\n46 2\n\nOutput\n\n7\n0 1 0 0 1 1 1\n\nInput\n\n2018 214\n\nOutput\n\n3\n92 205 1"},{"iden":"note","content":"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.\n\nIn the second example, _f_(_x_) = _x_2 + 205_x_ + 92 = (_x_ - 9)·(_x_ + 214) + 2018."}],"translated_statement":[{"iden":"statement","content":"为了整理旧物并迎接崭新的新年，彻底打扫房屋是必不可少的。\n\n小汤米找到了一个旧多项式，并通过对其取模另一个多项式进行了清理。但现在他后悔这样做了……\n\n给定两个整数 $p$ 和 $k$，找出一个系数为非负整数且严格小于 $k$ 的多项式 $f(x)$，使得它除以 $(x + k)$ 的余数为 $p$。即，$f(x) = q(x)·(x + k) + p$，其中 $q(x)$ 是一个多项式（不一定具有整数系数）。\n\n输入仅有一行，包含两个用空格分隔的整数 $p$ 和 $k$（$1 ≤ p ≤ 10^{18}$，$2 ≤ k ≤ 2 000$）。\n\n如果该多项式不存在，请输出单个整数 _-1_；否则，请输出两行。\n\n第一行输出一个非负整数 $d$ —— 多项式的系数个数。\n\n第二行输出 $d$ 个用空格分隔的整数 $a_0, a_1, ..., a_{d - 1}$，描述一个满足要求的多项式。你的输出需满足对所有 $0 ≤ i ≤ d - 1$，有 $0 ≤ a_i < k$，且 $a_{d - 1} ≠ 0$。\n\n如果存在多个可能的解，请输出任意一个。\n\n在第一个例子中，$f(x) = x^6 + x^5 + x^4 + x = (x^5 - x^4 + 3x^3 - 6x^2 + 12x - 23)·(x + 2) + 46$。\n\n在第二个例子中，$f(x) = x^2 + 205x + 92 = (x - 9)·(x + 214) + 2018$。\n"},{"iden":"input","content":"输入仅有一行，包含两个用空格分隔的整数 $p$ 和 $k$（$1 ≤ p ≤ 10^{18}$，$2 ≤ k ≤ 2 000$）。"},{"iden":"output","content":"如果该多项式不存在，请输出单个整数 _-1_；否则，请输出两行。第一行输出一个非负整数 $d$ —— 多项式的系数个数。第二行输出 $d$ 个用空格分隔的整数 $a_0, a_1, ..., a_{d - 1}$，描述一个满足要求的多项式。你的输出需满足对所有 $0 ≤ i ≤ d - 1$，有 $0 ≤ a_i < k$，且 $a_{d - 1} ≠ 0$。如果存在多个可能的解，请输出任意一个。"},{"iden":"examples","content":"输入\n46 2\n输出\n7\n0 1 0 0 1 1 1\n\n输入\n2018 214\n输出\n3\n92 205 1"},{"iden":"note","content":"在第一个例子中，$f(x) = x^6 + x^5 + x^4 + x = (x^5 - x^4 + 3x^3 - 6x^2 + 12x - 23)·(x + 2) + 46$。在第二个例子中，$f(x) = x^2 + 205x + 92 = (x - 9)·(x + 214) + 2018$。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ p \\in \\mathbb{Z} $, $ k \\in \\mathbb{Z} $ with $ 1 \\leq p \\leq 10^{18} $, $ 2 \\leq k \\leq 2000 $.  \nLet $ f(x) = \\sum_{i=0}^{d-1} a_i x^i $ be a polynomial with coefficients $ a_i \\in \\mathbb{Z} $, $ 0 \\leq a_i < k $, and $ a_{d-1} \\neq 0 $.  \n\n**Constraint**  \n$ f(-k) = p $  \n\n**Objective**  \nFind coefficients $ a_0, a_1, \\dots, a_{d-1} $ such that:  \n$$\nf(-k) = \\sum_{i=0}^{d-1} a_i (-k)^i = p\n$$  \nIf no such polynomial exists, output $-1$. Otherwise, output $ d $ and the sequence $ a_0, a_1, \\dots, a_{d-1} $.","simple_statement":null,"has_page_source":false}