No.2562 Digit Search Game (Green-or-Below Contest ver.)
タグ : / 解いたユーザー数 59
作問者 : 👑
Kyo_s_s
kusirakusira
Magentor
DeltaStruct
👑
rotti_coder
けんぴん
Problem Statement
Print one integer $X$ that satisfies all of the following conditions.
- $1 \leq X \leq 10^{18}$
- $X$ is a multiple of $M$.
- For each $i \ (1 \leq i \leq 9)$, the decimal representation of $X$ contains the digit $i$ at least $d_i$ times.
If there are multiple $X$ satisfying the conditions, you may print any of them. It can also be proved that, under the constraints of this problem, an $X$ satisfying the conditions always exists.
You are given $T$ test cases; answer each of them.
Constraints
- All input values are integers.
- $1 \leq T \leq 10^4$
- $1 \leq M \leq 10^9$
- $d_i \geq 0 \ (1 \leq i \leq 9)$
- $d_1 + d_2 + \dots + d_9 \leq 9$
Input
The input is given from Standard Input in the following format, where $case_i$ represents the $i$-th test case.
$T$ $case_1$ $case_2$ $\vdots$ $case_T$
Each case is given in the following format.
$M$ $d_1$ $d_2$ $d_3$ $d_4$ $d_5$ $d_6$ $d_7$ $d_8$ $d_9$
Output
Print $T$ lines. On the $i$-th line, print one integer $X$ satisfying the conditions for the $i$-th test case.
Sample
Sample 1
Input
3 7 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 9 998244353 0 1 2 2 1 0 0 1 2
Output
14 909090909090909090 998244353
For the $1$-st test case, since $d_1 = 1, d_4 = 1$, the decimal representation of $X$ must contain each of $1$ and $4$ at least $1$ time. Also, since $M = 7$, it must be a multiple of $7$. $X = 14$ satisfies the conditions.
Note that you do not need to minimize $X$, and that the digit $i$ may appear more than $d_i$ times. Therefore, for example, printing $X = 154$ or $X = 1414$ is also accepted.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。