| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 30 초 | 2048 MB | 3 | 1 | 1 | 50.000% |
Since the CCO often uses integers, Alice needs to learn about the integers! A positive integer $n$ can be written in base $b$ as the sequence $d_{m−1}d_{m−2} \dots d_1d_0$ if the following hold:
For example, the integer 2025ドル$ in base 19ドル$ is the sequence $(5, 11, 11)$ because 2025ドル = 5 \times 19^2 + 11 \times 19^1 + 11 \times 19^0$.
An integer $n$ is $b$-balanced if, when $n$ is written in base $b,ドル the average of the digits is $\frac{b − 1}{ 2}$.
For example, 2025ドル$ is 19ドル$-balanced because $\frac{5 + 11 + 11}{ 3} = 9 = \frac{19 − 1}{ 2}$.
Alice can easily find integers that are 19ドル$-balanced. However, she has trouble finding integers that are balanced in multiple ways. Given $B$ and $N,ドル please help Alice find the minimum integer $x$ such that:
The first line of input contains two space-separated integers $B$ and $N$ ($N ≥ 1$).
It is guaranteed that the answer does not exceed 10ドル^{18}$.
Output the minimum integer $x$ from the problem statement.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 2 | 2ドル ≤ B ≤ 7,ドル 1ドル ≤ N ≤ 10^4$ |
| 2 | 6 | 2ドル ≤ B ≤ 6,ドル $N = 10^{10}$ |
| 3 | 2 | 2ドル ≤ B ≤ 7$ |
| 4 | 9 | 8ドル ≤ B ≤ 11,ドル $N = 1$ |
| 5 | 4 | $B = 8$ |
| 6 | 2 | 9ドル ≤ B ≤ 11$ |
4 100
141
141ドル$ in base 2ドル$ is 10001101ドル$. The average digit is $\frac{1 + 0 + 0 + 0 + 1 + 1 + 0 + 1}{ 8} = 0.5 = \frac{2 − 1} {2}$. Therefore, 141ドル$ is 2ドル$-balanced.
141ドル$ in base 3ドル$ is 12020ドル$. The average digit is $\frac{1 + 2 + 0 + 2 + 0}{ 5} = 1 = \frac{3 − 1}{ 2}$. Therefore, 141ドル$ is 3ドル$-balanced.
141ドル$ in base 4ドル$ is 2031ドル$. The average digit is $\frac{2 + 0 + 3 + 1 }{4} = 1.5 = \frac{4 − 1 }{2}$. Therefore, 141ドル$ is 4ドル$-balanced.
Lastly, 141ドル ≥ 100$.
7 10000000000
16926961207710
Feel free to use these code snippets as part of your solution.
// Important: If x is 0, the result is undefined.
int base_2_length(unsigned long long x) {
return 64-__builtin_clzll(x);
}
int base_2_sum(unsigned long long x) {
return __builtin_popcountll(x);
}