Fredo is in a Hurry
Practice
3.3 (19 votes)
Ad Hoc
Approved
Basic programming
Easy
Problem
73% Success 8446 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Fredo lives in a building with \(N+1\) floors and his apartment is at floor N. The floors are numbered from 0 to N, N being the highest floor. Fredo has just come from school and is at floor 0. His favourite anime is about to start and he wants to reach his apartment as soon as possible.
He can either use staircase or elevator or a combination of both (use staircase for x floors and cover rest floors by elevator) to reach his apartment.

  • If he uses staircase, he takes f amount of time to reach floor f from floor \(f-1\).
  • Elevator takes 1 unit time to go from any floor to it's neighbouring floors.

The elevator currently is coming down from floor N .The elevator stops at the floor where the elevator button is pressed .From this floor, the elevator goes to floor N .
Tell him what is the minimum time he needs to reach floor N from floor 0.

Assumptions: Only Fredo uses the elevator during that period of time. Fredo will press the elevator button atmost once. If Fredo presses the elevator button at floor x, then the elevator needs to be at a floor \(\ge x\).

Input Format:
The first line consists of an integer T denoting the number of test cases.
The only line of each test consists of an integer N denoting the number of floors.

Output Format:
For each test case, print the minimum time Fredo needs to reach floor N from floor 0 in a separate line.

Input Constraints:
\(1 \le T \le 1000\)
\(1 \le N \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
58 votes
Tags:
ArraysEasyMath
Points:20
159 votes
Tags:
Ad-HocApprovedEasyOpen
Points:20
9 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementationJavaPythonQuick SortSorting