2 $s / 64$ $MB / 140$ points
Vla-tko, Vla-tko, Vla-tko!
Nobody comes to Vlatko’s office hours anymore. Angered, enraged and disgruntled, Vlatko’s
revenge is a convenient task for COCI:
You are given an infinite arithmetic sequence A(n) = $Cn + D$, defined for all natural numbers
$n$. We want find a sequence of $M$ distinct natural numbers $n$_{1}{}, n{2}{}, ..., n{M} less than or equal to
10^{15} such that the corresponding members of sequence A(n_{1}{}), A(n{2}{}), ..., A(n{M}_{}) all have the
same sum of digits in base $B$.
Please note: Every positive integer N can be written in base B as follows: create the unique
string $x$_{k}{}$x${$k-1$}{}...x{1}{}$x${0}{}, where 0 ≤$x${i} < $B$ for each $i$, and the equation $x$_{k}{}$B$^{k} + x{$k-1$}{}$B$^{$k-1$} + ... + $x${1}{}$B + x${0} =
$N$ is satisfied. The sum of digits is given with $x$_{k}{} + ... + x{0}_{}.
Input
The first line of input contains four integers $C$, $D$, $B$ and $M$ (1 ≤ C, $D$ ≤ 10000, $2 \le B \le 5000$, 1 ≤ $M$ ≤ 250000).
Output
The first and only line of output must contain the required numbers, separated by spaces, in
an arbitrary order. Please note: you must output the numbers $n$_{i}{}, not numbers A(n{i}_{}). All numbers in the
output should be less than or equal to 10^{15}^{}. The input data will be such that a solution that meets the given conditions exists.
Example 1
5 3 2 2 2 1 10 3
output 2 5 2 20 200
Clarification of the test cases: In the first test case, one of the possible sequences is the sequence in the output. The corresponding
members of the arithmetic sequence are 5 * 2 + 3 = 13 and 5 * 5 + 3 = 28. The format of number 13 in
base 2 is 1101, whereas the format of number 28 in base 2 is 11100. The sum of digits in both
formats is equal to 3.
In the second test case, the corresponding members of the sequence are 2 * 2 + 1 = 5, 2 * 20 + 1 =
41, and 2 * 200 + 1 = 401. Each of the numbers’ digits, written in base 10, sum up to 5.
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.