CF1225C p-binary
题目描述
### 题意简述
给定整数 $n,p$,求最小的 $x$ 使得其满足
$$\sum_{1}^{x} (2^k+p)=n$$
其中 $k$ 可以是任意自然数。
输入格式
一行,$n,p(1\leq n \leq 10^9,-1000\leq p \leq 1000)$。
输出格式
如果找不到这样的 $x$ 请输出 $-1$。
否则输出 $x$。
说明/提示
$ 0 $ -binary numbers are just regular binary powers, thus in the first sample case we can represent $ 24 = (2^4 + 0) + (2^3 + 0) $ .
In the second sample case, we can represent $ 24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1) $ .
In the third sample case, we can represent $ 24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1) $ . Note that repeated summands are allowed.
In the fourth sample case, we can represent $ 4 = (2^4 - 7) + (2^1 - 7) $ . Note that the second summand is negative, which is allowed.
In the fifth sample case, no representation is possible.