Canadian Computing Olympiad 2025: Day 1, Problem 3
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
.
.
Input Specification
The first line of input contains two space-separated integers and
.
It is guaranteed that the answer does not exceed .
The following table shows how the available 25 marks are distributed:
Marks Awarded | Bounds on |
Bounds on |
---|---|---|
2 marks | |
|
6 marks | |
|
2 marks | |
None |
9 marks | |
|
4 marks | |
None |
2 marks | |
None |
Output Specification
Output the minimum integer from the problem statement.
Sample Input 1
4 100
Output for Sample Input 1
141
Explanation for Sample Output 1
in base
is
. The average digit is
. Therefore,
is
-balanced.
in base
is
. The average digit is
. Therefore,
is
-balanced.
in base
is
. The average digit is
. Therefore,
is
-balanced.
Lastly, .
Sample Input 2
7 10000000000
Sample Output 2
16926961207710
Hint
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);
}
Comments