#P5956. [POI 2017] Podzielno
[POI 2017] Podzielno
Problem Description
In base , for each digit , you have copies. You need to use these digits to form the largest base- number (no leading zeros, and you do not need to use all digits), such that is a multiple of . There are queries. For each query, ask what the digit at position of is in base (the least significant digit is position ).
Input Format
The first line contains two positive integers .
The second line contains positive integers .
The next lines each contain one integer , representing a query.
Output Format
Output lines, each containing one integer, answering the queries in order. If that position does not exist, output .
3 3
1 1 1
0
1
2
0
2
-1
Hint
Constraints: for of the testdata, , , , .
Translated by ChatGPT 5