Balanced Integer
시간 제한30초메모리 제한2048 MB
2부터 B까지 모든 진법 b에서 b진법 자릿수의 평균이 (b-1)/2가 되는, N 이상인 최소 정수 x를 구한다.
문제
Since the CCO often uses integers, Alice needs to learn about the integers! A positive integer can be written in base as the sequence if the following hold:
- Each digit is between and , inclusive.
- .
- .
For example, the integer in base is the sequence because .
An integer is -balanced if, when is written in base , the average of the digits is .
For example, is -balanced because .
Alice can easily find integers that are -balanced. However, she has trouble finding integers that are balanced in multiple ways. Given and , please help Alice find the minimum integer such that:
- is -balanced, for all .
- .
입력
The first line of input contains two space-separated integers and ().
It is guaranteed that the answer does not exceed .
출력
Output the minimum integer from the problem statement.
힌트
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);
}