Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Game of Lands

By RasheedAbid · Limits 500ms, 512 MB

Two big houses, The Lanisters and the Starks are fighting over the 7 kingdoms having infinite lands. To stop the war and to bring peace Danny came up with a solution. She will denote each land with a positive integer number. Then the Lannisters will make 1 move and take odd number of lands starting from 1. Then the Starks will start after 1, make two moves and take two even numbered lands, which are 2 and 4 respectively. Then the Lannisters will make 3 moves and take three odd numbered lands after 4, that are 5,7,9. And so on. One can take only one land in a single move. Also one land can only be taken once.

Danny is good with dragons. But a meteorite crash killed all the dragons. So now she has hired Jon Snow to do her job, that is determining who will take which numbered land at a specific move.


First line will take an integer T. The number of test cases. The following T lines will take an integer n.

1<= T <= 1000
1<= n <= 1,000,000,000,000,000


Print the case number and the number of that land, which will be taken at the n-th move.


Input Output
Case 1: 1
Case 2: 4
Case 3: 10



76% Solution Ratio

mrinmoy29aEarliest, Oct '17

nahid08Fastest, 96.0s

mrinmoy29aLightest, 131 kB

fkabir_nstuShortest, 333B


Login to submit

Related Contests

18th IUT Computer Programming Contest 2017 Ended at 2017-10-04 12:20:00 +0000 UTC
Replay of 18th IUT Computer Programming Contest 2017 Ended at 2017-10-11 16:00:00 +0000 UTC