PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000055. Phân số kế tiếp trong dãy hữu tỉ (A Rational Sequence)
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ố kế tiếp trong dãy hữu tỉ (A Rational Sequence)
A Rational Sequence
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the binary tree rooted at 1/1 where the left child of p/q is p/(p+q) and the right child is (p+q)/q. A breadth-first, left-to-right traversal produces a sequence of reduced positive fractions. Given a fraction p/q in this sequence, output the fraction immediately following it.
Input
A single reduced positive fraction p/q, without a dataset identifier.
Output
The next reduced fraction in the form a/b.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , ; the next fraction fits in signed 64-bit integers.
Examples
Input
1/1
Output
1/2
Explanation
The breadth-first successor of root 1/1 is its left child 1/2.