Logo
(追記) (追記ここまで)

13077번 - Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1221007486.047%

문제

We inductively label the nodes of a rooted binary tree with an infinite number of nodes as follows:

  • The root is labeled by 1/1,
  • If the label of a node is p/q, then
    • The label of its left child is p/(p+q), and
    • The label of its right child is (p+q)/q.

By having this tree in our hand, we define a rational sequence a1, a2, a3, … by a breadth first traversal of the tree in such a way that nodes in the same level are visited from left to right. Therefore, we have a1 = 1/1, a2 = 1/2, a3 = 2/1, a4 = 1/3, a5 = 3/2, …

You are to write a program that gets values p and q and computes an integer n for which an = p/q.

입력

The first line of the input includes the number of test cases, 1 ≤ t ≤ 1000. Each test case consists of one line. This line contains p, followed by / and then q without any space between them.

출력

For each test case, output in one line an integer n for which an = p/q. It is guaranteed that in all test cases n fits in a 32-bit integer.

제한

예제 입력 1

4
1/1
1/3
5/2
2178309/1346269

예제 출력 1

1
4
11
1431655765

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > Iran Internet Programming Contest > IIPC 2015 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /