Advertisement
CooBin

rectangle

Jul 17th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define FILE "MATRIX"
  3. using namespace std;
  4.  
  5. typedef unsigned long long ll;
  6.  
  7. const ll inf = 1e10;
  8.  
  9. ll getRect(ll size){
  10.     if (!size) return 0;
  11.     if (size == 1) return 1;
  12.     if (size % 2 == 0) return size / 2 * size;
  13.     ll B = (size + 1) / 2, S = size - B;
  14.     return B * B + S * S;
  15. }
  16.  
  17. ll getEven(ll lim){
  18.     ll d = 1, c = inf / 2, ans = c;
  19.     while (d <= c){
  20.         ll mid = (d + c) / 2;
  21.         ll xSize = mid - 1;
  22.         ll num = 4LL * getRect(xSize);
  23.         if (num >= lim) ans = mid * 2, c = mid - 1;
  24.         else d = mid + 1;
  25.     }
  26.     return ans;
  27. }
  28.  
  29. ll getOdd(ll lim){
  30.     ll d = 0, c = (inf - 2 ) / 2, ans = c;
  31.     while (d <= c){
  32.         ll mid = (d + c) / 2;
  33.         if (getRect(mid * 2 + 1) >= lim) ans = mid * 2 + 1, c = mid - 1;
  34.         else d = mid + 1;
  35.     }
  36.     return ans;
  37. }
  38.  
  39. main(){
  40.     freopen(FILE".inp", "r", stdin);
  41.     freopen(FILE".out", "w", stdout);
  42.     ll n;
  43.     cin >> n;
  44.     if (n <= 1) {cout << n; return 0;}
  45.     if (n == 3) { cout << 5; return 0;}
  46.     ll ans = min(getEven(n), getOdd(n));
  47.     cout << ans << '\n';
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement