QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#6129. 魔法乘法

統計

BaoBao 正在他的魔法书中学习两个正整数之间的一种新的二元运算,记作 $\otimes$。书中告诉他,该运算的结果是通过将两个整数中每一位数字的乘积结果拼接在一起得到的。

形式化地,设第一个整数为 $A = a_1 a_2 \dots a_n$,其中 $a_i$ 表示 $A$ 的第 $i$ 位数字;第二个整数为 $B = b_1 b_2 \dots b_m$,其中 $b_i$ 表示 $B$ 的第 $i$ 位数字。我们有:

$$A \otimes B = \sum_{i=1}^{n} \sum_{j=1}^{m} a_i b_j = a_1 b_1 + a_1 b_2 + \dots + a_1 b_m + a_2 b_1 + \dots + a_n b_m$$

注意,$a_i b_j$ 的结果被视为一个字符串(若 $a_i b_j > 0$ 则不含前导零,若 $a_i b_j = 0$ 则恰好包含一个 '0'),而不是一个普通的整数。此外,这里的求和指的是字符串拼接,而不是普通的加法运算。

例如,$23 \otimes 45 = 8101215$。因为 $8 = 2 \times 4$,$10 = 2 \times 5$,$12 = 3 \times 4$ 且 $15 = 3 \times 5$。

BaoBao 非常聪明,很快就学会了如何进行 $\otimes$ 的逆运算。现在他给你一个 $\otimes$ 运算的结果以及两个原始整数的位数,请帮他还原出这两个原始整数 $A$ 和 $B$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个正整数 $n$ 和 $m$ ($1 \le n, m \le 2 \times 10^5$),其中 $n$ 表示 $A$ 的长度,$m$ 表示 $B$ 的长度。此处整数的长度是指该数在十进制表示下不含前导零时的字符串长度。

第二行包含一个正整数 $C$(不含前导零),表示 $A \otimes B$ 的结果。$C$ 的长度不超过 $2 \times 10^5$。

保证所有测试数据中 $C$ 的长度之和不超过 $2 \times 10^6$。

输出格式

对于每组测试数据,输出一行。

如果存在满足 $A \otimes B = C$ 的 $A$ 和 $B$,输出一行,包含两个由空格分隔的整数 $A$ 和 $B$。注意,$A$ 和 $B$ 应为不含前导零的正整数,$A$ 的长度应恰好为 $n$,$B$ 的长度应恰好为 $m$。

如果存在多个合法的答案,输出 $A$ 最小的那个;如果仍有多个答案,输出其中 $B$ 最小的那个。

如果不存在这样的 $A$ 和 $B$,则输出一行 "Impossible"(不含引号)。

样例

样例输入 1

4
2 2
8101215
3 4
100000001000
2 2
80101215
3 4
1000000010000

样例输出 1

23 45
101 1000
Impossible
Impossible

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.