In this

**HackerEarth Fredo is in a Hurry problem solution**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 favorite anime is about to start and he wants to reach his apartment as soon as possible.He can either use a 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 a staircase, he takes f amount of time to reach floor f from floor f - 1.

An elevator takes 1 unit of time to go from any floor to it's neighboring 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.

## HackerEarth Fredo is in a Hurry problem solution.

`#include<bits/stdc++.h>`

using namespace std;

#define ll long long

int main()

{

int t;

cin>>t;

while(t--)

{

ll n;

cin>>n;

if(n==1){cout<<"1\n";continue;}

ll x=floor((-3.0+sqrt(9.0+8.0*double(n)))/2.0);

cout<<2*(n-x)<<"\n";

}

return 0;

}

## 0 Comments