Logo
(追記) (追記ここまで)

34525번 - Balanced Integer 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
30 초 2048 MB31150.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:

  • Each digit $d_i$ is between 0ドル$ and $b − 1,ドル inclusive.
  • $d_{m−1} > 0$.
  • $n = d_{m−1} \times b^{m−1} + d_{m−2} \times b^{m−2} + \cdots + d_1 \times b^1 + d_0 \times b^0$.

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:

  • $x$ is $b$-balanced, for all 2ドル ≤ b ≤ B$.
  • $x ≥ N$.

입력

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.

제한

서브태스크

번호배점제한
12

2ドル ≤ B ≤ 7,ドル 1ドル ≤ N ≤ 10^4$

26

2ドル ≤ B ≤ 6,ドル $N = 10^{10}$

32

2ドル ≤ B ≤ 7$

49

8ドル ≤ B ≤ 11,ドル $N = 1$

54

$B = 8$

62

9ドル ≤ B ≤ 11$

예제 입력 1

4 100

예제 출력 1

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$.

예제 입력 2

7 10000000000

예제 출력 2

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);
}

출처

Olympiad > Canadian Computing Competition & Olympiad > 2025 > CCO 2025 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /