#GL0000059. Mã đường đi trong cây Stern–Brocot (The Stern-Brocot Number System)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mã đường đi trong cây Stern–Brocot (The Stern-Brocot Number System)
The Stern-Brocot Number System
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Each node of the Stern–Brocot tree is determined by a left bound and a right bound . Its value is : add the two numerators and add the two denominators.
The root uses bounds and , so its value is . Here denotes a positive-infinity boundary, not an ordinary fraction.
From a node , an L step keeps the left bound and replaces the right bound by . An R step replaces the left bound by and keeps the right bound. Compute the child value from the updated bounds using the same rule.
Given a reduced positive fraction different from , output the sequence of L and R steps from the root to its node.
Input
Two positive coprime integers p and q with p != q.
Output
The string of L and R characters.
Subtasks
- Subtask 1 (20 points): ; path length at most .
- Subtask 2 (30 points): ; path length at most .
- Subtask 3 (50 points): ; path length at most .
Examples
Input
5 7
Output
LRRL
Explanation
The path to 5/7 is L, R, R, L.