시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 512 MB | 66 | 49 | 43 | 76.786% |
Consider an infinite complete binary tree where the root node is 1/1 and left and right childs of node p/q are p/(p+q) and (p+q)/q, respectively. This tree looks like:
1/1 ______|______ | | 1/2 2/1 ___|___ ___|___ | | | | 1/3 3/2 2/3 3/1 ...
It is known that every positive rational number appears exactly once in this tree. A level-order traversal of the tree results in the following array:
1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, ...
Please solve the following two questions:
The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of one line. The line contains a problem id (1 or 2) and one or two additional integers:
For each test case:
Case #x: p q
", where x
is the case number (starting from 1), and p
, q
are numerator and denominator of the asked array element, respectively.Case #x: n
", where x
is the case number (starting from 1), and n
is the position of the given number.4 1 2 2 1 2 1 5 2 3 2
Case #1: 1 2 Case #2: 2 Case #3: 3 2 Case #4: 5
Contest > Google > Google's Coding Competitions > Google of Greater China Test for New Grads of 2014 > Round A China New Grad Test 2014 B1번
Contest > Google > Kick Start > Google Kick Start 2013 > Round A C1번