Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define FILE "MATRIX"
- using namespace std;
- typedef unsigned long long ll;
- const ll inf = 1e10;
- ll getRect(ll size){
- if (!size) return 0;
- if (size == 1) return 1;
- if (size % 2 == 0) return size / 2 * size;
- ll B = (size + 1) / 2, S = size - B;
- return B * B + S * S;
- }
- ll getEven(ll lim){
- ll d = 1, c = inf / 2, ans = c;
- while (d <= c){
- ll mid = (d + c) / 2;
- ll xSize = mid - 1;
- ll num = 4LL * getRect(xSize);
- if (num >= lim) ans = mid * 2, c = mid - 1;
- else d = mid + 1;
- }
- return ans;
- }
- ll getOdd(ll lim){
- ll d = 0, c = (inf - 2 ) / 2, ans = c;
- while (d <= c){
- ll mid = (d + c) / 2;
- if (getRect(mid * 2 + 1) >= lim) ans = mid * 2 + 1, c = mid - 1;
- else d = mid + 1;
- }
- return ans;
- }
- main(){
- freopen(FILE".inp", "r", stdin);
- freopen(FILE".out", "w", stdout);
- ll n;
- cin >> n;
- if (n <= 1) {cout << n; return 0;}
- if (n == 3) { cout << 5; return 0;}
- ll ans = min(getEven(n), getOdd(n));
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement