Skip to content

Instantly share code, notes, and snippets.

@Shravan40
Created October 24, 2014 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shravan40/cc9c509d325c0c959df6 to your computer and use it in GitHub Desktop.
Save Shravan40/cc9c509d325c0c959df6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int min = floor(sqrt(n));
int max = ceil(sqrt(n));
int res;
if(min == max)
{
res = (min-1)*2;
}
else
{
if(n > (min*max))
res = (max-1)*2;
else
{
res = (min-1)*2+1;
}
}
cout<<res<<"\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment