Jumpy Ball
Submissions: 3314   Accuracy:

30.9%

  Difficulty: Basic   Marks: 1

You have a jumpy ball. You throw it up from the ground upto a height of H. The ball is jumpy, so when it comes back to the ground, it rebounds and goes up again to a distance of floor(H/2). This keeps on repeating till it can't rebound anymore. You need to find the total distance travelled by the ball.

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test case follows. Each testcase contains a single line having H as input.

Output:
For each testcase, print the total distance travelled.

Constraints:
1<=T<=105
0<=H<=1015

Example:

Input:
3
10
20
30

Output:
36
76
112

For testcase 1: H is 10. From ground to H it travels d=10. From H to ground it travels d=10+10. Now H becomes floor(10/2). So ball rebounds to d=10+10+5. It goes down to ground. d=10+10+5+5. Now H becomes floor(5/2). So ball rebounds to d=10+10+5+5+2. The ball goes down. d=10+10+5+5+2+2. H becomes floor(2/2). So ball rebounds to d=10+10+5+5+2+2+1. It goes down to ground. d=10+10+5+5+2+2+1+1. H becomes floor(1/2). H is zero so no rebound. total d=36.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ankit Sharma
Author: Soul_xhacker


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.