PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000056. Chỉ số của phân số (A Rational Sequence 2)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chỉ số của phân số (A Rational Sequence 2)
A Rational Sequence 2
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
In the infinite binary tree rooted at 1/1, the children of p/q are p/(p+q) and (p+q)/q. Number all vertices in breadth-first, left-to-right order, starting at 1. Given a reduced fraction p/q, find its one-based position n in that order.
Input
A single reduced positive fraction p/q, without a dataset identifier.
Output
The one-based integer index n.
Subtasks
- Subtask 1 (20 points): are positive coprime integers with for ; the index is not given in the input.
- Subtask 2 (30 points): are positive coprime integers with for ; the index is not given in the input.
- Subtask 3 (50 points): are positive coprime integers with for ; the index is not given in the input.
Examples
Input
5/2
Output
11
Explanation
The binary index of 5/2 is 1011, which equals 11 in decimal.