COCI '17 Contest 6 #5 Kotrljanje

View as PDF

Submit solution

Points: 17 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem type

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 to find a sequence of M distinct natural numbers n1,n2,,nM less than or equal to 1015 such that the corresponding members of sequence A(n1),A(n2),,A(nM) 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 xkxk1x1x0, where 0xi<B for each i, and the equation xkBk+xk1Bk1++x1B+x0=N is satisfied. The sum of digits is given with xk++x0.

Input Specification

The first line of input contains four integers C, D, B and M (1C,D10000,2B5000,1M250000).

Output Specification

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 ni, not numbers A(ni). All numbers in the output should be less than or equal to 1015.

The input data will be such that a solution that meets the given conditions exists.

Sample Input 1

Copy
5 3 2 2

Sample Output 1

Copy
2 5

Explanation for Sample Output 1

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.

Sample Input 2

Copy
2 1 10 3

Sample Output 2

Copy
2 20 200

Explanation for Sample Output 2

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.


Comments

There are no comments at the moment.