QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#4771. 鸟树

统计

Bird tree 是一棵无限二叉树,其前 5 层如下所示:

它可以定义如下:

$$bird = \begin{array}{ccc} & 1/1 & \\ \swarrow & & \searrow \\ 1/(bird + 1) & & (1/bird) + 1 \end{array}$$

这是一个共递归定义,其中两个 $bird$ 都指代完整的(无限)树。表达式 $bird + 1$ 表示将树中的每个分数都加上 1,$1/bird$ 表示将树中的每个分数取倒数(即 $a/b$ 变为 $b/a$)。

令人惊讶的是,这棵树恰好包含每个正有理数一次,因此每个最简分数都在树中占据唯一的位置。因此,我们也可以通过给出 Bird tree 中的方向(L 表示左子树,R 表示右子树)来描述一个有理数。例如,$2/5$ 表示为 LRR。给定一个最简分数,返回一个由 L 和 R 组成的字符串:即从树顶到达该分数的路径方向。

输入格式

第一行是一个正整数:测试用例的数量,最多 100 个。之后每个测试用例包含:

  • 一行包含两个整数 $a$ 和 $b$ ($1 \le a, b \le 10^9$),由 '/' 分隔。它们代表一个最简分数的分子和分母。整数 $a$ 和 $b$ 不全为 1,且满足 $\gcd(a, b) = 1$。

对于每个测试用例,方向字符串的长度最多为 10 000。

输出格式

对于每个测试用例:

  • 一行输出该分数在 Bird tree 中位置的字符串表示。

样例

输入格式 1

3
1/2
2/5
7/3

输出格式 1

L
LRR
RLLR

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.