問題一覧 > 通常問題

No.2562 Digit Search Game (Green-or-Below Contest ver.)

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 59
作問者 : 👑 AngrySadEight / テスター : deuteridayo Kyo_s_s kusirakusira Magentor DeltaStruct 👑 loop0919 rotti_coder マベマス(mavemas_413) けんぴん aki
お気に入りにしたユーザー ProblemId : 10300 / 自分の提出
問題文最終更新日: 2023-11-30 18:44:54
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
第2回緑以下コンテスト (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。