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