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. // 5
  25. // 3
  26. // 5
  27. // 2
  28. // 999997
  29. // 999999
  30.  
  31.  
  32.  
  33. int count(int n, int mid){
  34.  
  35. int ct = 0;
  36. for(int i=1; i<=n; i++){
  37. ct += min( mid/i , n );
  38. }
  39. return ct;
  40.  
  41. }
  42.  
  43.  
  44.  
  45. int consistency1(int n){
  46. if(n==1) return 1;
  47. int s = 1, e = n*n;
  48. int ans = LINF;
  49. while(s<=e){
  50. int mid = s + (e-s)/2;
  51. if(count(n, mid) >= (n*n+1)/2 ){
  52. ans = min(ans, mid);
  53. e = mid-1;
  54. }
  55. else s = mid+1;
  56. }
  57.  
  58. return ans;
  59.  
  60. }
  61.  
  62.  
  63. int consistency2(int n){
  64. int s = 1;
  65. int e = n*n;
  66. int total = n*n;
  67.  
  68. while(s<e){
  69. int mid = s + (e-s)/2;
  70. if(count(n, mid) >= (total+1)/2){
  71. e = mid;
  72. }
  73. else s = mid+1;
  74. }
  75.  
  76. return e;
  77.  
  78. }
  79.  
  80. void solve() {
  81.  
  82. int n;
  83. cin>>n;
  84.  
  85. cout << consistency1(n) << " " << consistency2(n) << endl;
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. int32_t main() {
  95. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  96.  
  97. int t = 1;
  98. cin >> t;
  99. while (t--) {
  100. solve();
  101. }
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 1.45s 5304KB
stdin
5
3
5
2
999997
999999
stdout
3 3
8 8
2 2
186681673010 186681673010
186682420008 186682420008