Skip to content

Instantly share code, notes, and snippets.

@qjatn0120
Created March 23, 2023 17:37
Show Gist options
  • Save qjatn0120/8f7301219921c2d5991c997ad60d31e5 to your computer and use it in GitHub Desktop.
Save qjatn0120/8f7301219921c2d5991c997ad60d31e5 to your computer and use it in GitHub Desktop.
#ifdef DEBUG
#include "debug.h"
#endif // DEBUG
#ifndef DEBUG
template <typename T>
void debug(T &x){}
template <typename T>
void debug(T &x, int i, int j){}
#endif // DEBUG
#include <bits/stdc++.h>
using namespace std;
long long int getChip(long long int dist){
if(dist & 1) return ((dist + 1) / 2) * ((dist + 1) / 2) * 4;
return 1 + (dist / 2) * (dist / 2 + 1) * 4;
}
int main(){
cin.tie(nullptr), ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--){
long long int n;
cin >> n;
long long int lo = 0, hi = 1e9;
while(lo < hi){
long long int mid = (lo + hi) >> 1;
if(getChip(mid) >= n) hi = mid;
else lo = mid + 1;
}
cout << lo << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment