fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24.  
  25. int count(int n, int mid){
  26. int ct = 0;
  27. for(int i=1; i<=n; i++){
  28. int val = min(n, mid/i);
  29. ct += val;
  30. }
  31. return ct;
  32. }
  33. int consistency(int n){
  34. if(n==1) return 1;
  35. int s = 1, e = n*n;
  36. int ans = LINF;
  37. while(s<=e){
  38. int mid = s + (e-s)/2;
  39. if(count(n, mid) >= (n*n+1)/2 ){
  40. ans = min(ans, mid);
  41. e = mid-1;
  42. }
  43. else s = mid+1;
  44. }
  45.  
  46. return ans;
  47.  
  48. }
  49.  
  50. void solve() {
  51.  
  52. int n;
  53. cin>>n;
  54.  
  55. cout << consistency(n) << endl;
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. int32_t main() {
  65. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  66.  
  67. int t = 1;
  68. cin >> t;
  69. while (t--) {
  70. solve();
  71. }
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.84s 5320KB
stdin
5
3
5
2
999997
999999
stdout
3
8
2
186681673010
186682420008