Chef and Segment Game
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Chef loves to play games. Now he plays very interesting game called "Segment". At the beginning Chef has segment [0, X] and no points on it. On each step Chef chooses the subsegment of maximal length possible such as it contains no points on it. If there are more than one such subsegment Chef chooses the one with the minimal left coordinate. Once Chef chosed the subsegment he put the point in it's middle and the step is over.
Help Chef to define the coordinate of the point he will put on the K-th step.
- The first line contains integer T - number of test cases.
- Each of next T lines contains two integers X and K.
- For each test case in a single line print single double number - the coordinate of the K-th point Chef will put. Answer will be considered as correct if absolute difference between the answer and correct answer is less or equal 10^(-6).
- 1 ≤ T ≤ 10^5
- 1 ≤ X ≤ 10^9
- 1 ≤ K ≤ 10^12
- Subtask 1: T ≤ 10; X, K ≤ 20. Points: 15
- Subtask 2: T ≤ 10; X ≤ 10^6, K ≤ 2*10^5. Points: 25
- Subtask 3: T ≤ 10^5; X ≤ 10^9, K ≤ 10^12. Points: 60
Input: 4 10 1 10 2 10 3 1000000000 1234567 Output: 5.0000 2.5000 7.5000 177375316.6198730500000000
You can see the points coordinates for the third sample from first two samples.
|Tags||ad-hoc, berezin, nov14, simple|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions