PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000057. Phân số ở vị trí N (A Rational Sequence Take 3)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phân số ở vị trí N (A Rational Sequence Take 3)
A Rational Sequence (Take 3)
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
In the infinite binary tree rooted at 1/1, the left child of p/q is p/(p+q) and the right child is (p+q)/q. Its breadth-first, left-to-right traversal defines F(1)=1/1, F(2)=1/2, F(3)=2/1, etc. Given a one-based index n, output the exact reduced fraction F(n).
Input
A single integer n.
Output
The reduced fraction p/q.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
11
Output
5/2
Explanation
Index 11 has binary representation 1011. Following L, R, R from the root gives 5/2.