QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#15820. Recurring Decimal to Fractions

统计

给定两个表示小于 1 的循环小数的数字字符串。第一个字符串 $s_1$ 表示循环小数小数点后的非循环部分,第二个字符串 $s_2$ 表示循环小数的循环部分,例如:

1 012 表示 $0.1\overline{012}$

返回两个整数 $n, d$,表示该分数的分子和分母。这两个整数应当互质。

输入格式

第一行包含一个整数 $T (\le 40)$,表示测试用例的数量。每个测试用例包含三行。对于每个测试用例,第一行有两个用空格分隔的整数 $a$ 和 $b$。第二行是一个长度为 $a$ 的字符串 $s_1$,第三行是一个长度为 $b$ 的字符串 $s_2$。

输出格式

每个测试用例输出两个用空格分隔的整数 $n$ 和 $d$。第一个整数 $n$ 是分子,第二个整数 $d$ 是分母。必须对分数进行化简,使得分子和分母互质。

数据范围

  • $1 \le a$
  • $1 \le b$
  • $1 \le a + b \le 10$

样例

输入 1

2
1 3
0
012
3 1
085
3

输出 1

2 1665
32 375

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.