217692026-01-13 20:36:36hunzombiAutókódoláscpp17Accepted 50/501ms508 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll findHigh(ll n) {
    ll c = n, c0 = 0, c1 = 0;
    while ((c & 1) == 0 && c != 0 ) {
        c0++;
        c >>= 1;
    }
    while ((c & 1) == 1) {
        c1++;
        c >>= 1;
    }
    if (c0 + c1 == 0 || c0 + c1 == 63) return -1;
    return n + (1LL << c0) + (1LL << (c1 - 1)) - 1;
}

ll findLow(ll n) {
    ll temp = n, c0 = 0, c1 = 0;
    while ((temp & 1) == 1) {
        c1++;
        temp >>= 1;
    }
    if (temp == 0) return -1;
    while ((temp & 1) == 0 && temp != 0) {
        c0++;
        temp >>= 1;
    }
    return n - (1LL << c1) - (1LL << (c0 - 1)) + 1;
}

int main()
{
    ll n;
    cin >> n;
    cout << findLow(n) << '\n' << findHigh(n) << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms396 KiB
7Accepted2/21ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms508 KiB
10Accepted4/41ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/41ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Accepted4/41ms508 KiB
16Accepted4/41ms508 KiB
17Accepted4/41ms316 KiB