Print a polynomial using minimum number of calls

血红的双手。 提交于 2019-12-04 00:14:39

Here's a neat trick.

int N = poly(1)

Now we know that every coefficient in the polynomial is at most N.

int B = poly(N+1)

Now expand B in base N+1 and you have the coefficients.


Attempted explanation: Algebraically, the polynomial is

poly = p_0 + p_1 * x + p_2 * x^2 + ... + p_k * x^k

If you have a number b and expand it in base n, then you get

b = b_0 + b_1 * n + b_2 * n^2 + ...

where each b_i is uniquely determined and b_i < n.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!