15872022-11-28 16:43:06kovacs.peter.18fAutókódoláscpp11Accepted 50/503ms3916 KiB
#include <iostream>

using namespace std;

long long N;

int bitcount(long long n) {
    int result = 0;
    while (n) {
        n &= n - 1;
        ++result;
    }
    return result;
}

long long following(long long n) {
    n |= n - 1;
    ++n;
    n += (1LL << bitcount(N) - bitcount(n)) - 1;
    return n;
}

long long previous(long long n) {
    n &= n + 1;
    --n;
    n ^= (1LL << bitcount(n) - bitcount(N)) - 1;
    return n;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    cout << (bitcount(N + 1) == 1 ? -1 : previous(N)) << '\n' << following(N) << '\n';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1892 KiB
2Accepted0/02ms2084 KiB
3Accepted2/22ms2156 KiB
4Accepted2/22ms2288 KiB
5Accepted2/22ms2364 KiB
6Accepted2/22ms2392 KiB
7Accepted2/22ms2592 KiB
8Accepted4/42ms2796 KiB
9Accepted4/42ms2876 KiB
10Accepted4/42ms3000 KiB
11Accepted4/42ms3204 KiB
12Accepted4/42ms3404 KiB
13Accepted4/42ms3612 KiB
14Accepted4/42ms3692 KiB
15Accepted4/42ms3916 KiB
16Accepted4/42ms3896 KiB
17Accepted4/42ms3892 KiB