2152. Digits

单点时限: 2.0 sec

内存限制: 256 MB

Let d be a digit and n be a positive number. A sequence of numbers t1, t2, . . . , tm is a d-sum of n if

  • t1 + t2 + · · · + tm = n, and

  • t1, t2, . . . , tm are numbers expressed using only the digit d. For example, if d = 2 then ti could be 2, 22, 222, . . .

输入格式

The first line of input gives the number of cases, N(1<=N<=20). N test cases follow.Each line of the input contains a digit d(0<=d<10) and a positive number n(1<=n<=10000000), in that order.

输出格式

For each test case, first output a line containing “Case #M:”, where M is the number of the test case,then each line of input specifying a digit d and positive number n, output a line con-taining d, a line containing n and a d-sum of n having minimum number of terms m, and a line containing the number of terms m. If no d-sum of n exists, output a message to that effect.

样例

Input
2
3 402
5 64
Output
Case #1:
d = 3
n = 402 = 333 + 33 + 33 + 3
a shortest summation with m = 4 terms.
Case #2:
d = 5
n = 64
has no such summation.
HintL:
The output formats:
Case□#d:
d□=□d
n□=□d□=□d□+□d□+□d
a□shortest□summation□with□m□=□4□terms. "□" represent a whitespace

9 人解决,23 人已尝试。

10 份提交通过,共有 43 份提交。

7.4 EMB 奖励。

创建: 16 年,5 月前.

修改: 7 年,2 月前.

最后提交: 4 年,8 月前.

来源: N/A

题目标签