16042022-11-28 20:37:00kicsiboglarAutókódoláscpp11Runtime error 0/503ms3988 KiB

#include <iostream>
#define ll long long 

using namespace std;

ll n, i, db=0;

bool construct(ll a, bool ok)
{
    ll nrb=0;
    while (a > 0)
    {
        if (a % 2 == 1) nrb++;
        a = a / 2;
    }
    if (ok) db = nrb;
    else if (nrb == db) return true;
    else return false;
}

int main()
{
   // ios::sync_with_stdio(false);
    cin >> n;
    construct(n, true);
    //cout << db;
    if(db == 1)
    {
        cout << n / 2 << "\n" << n * 2;
        return 0;
    }
    i = n - 1;
    while (i>=1)
    {
        if (construct(i, false))
        {
            cout << i;
            break;
        }
        --i;
    }
    if (i == 0) cout << "-1";
    cout << "\n";

    i = n + 1;
    bool ok = false;
    while (!ok)
    {
        ok = construct(i, false);
        if (ok)
        {
            cout << i;
            return 0;
        }
        ++i;
    }
    cout << "-1";
    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/03ms1976 KiB
2Runtime error0/02ms2168 KiB
3Runtime error0/22ms2368 KiB
4Runtime error0/23ms2924 KiB
5Runtime error0/22ms2988 KiB
6Runtime error0/22ms3176 KiB
7Runtime error0/22ms3164 KiB
8Runtime error0/42ms3364 KiB
9Runtime error0/42ms3644 KiB
10Runtime error0/42ms3988 KiB
11Runtime error0/42ms3760 KiB
12Runtime error0/42ms3564 KiB
13Runtime error0/42ms3840 KiB
14Runtime error0/42ms3884 KiB
15Runtime error0/42ms3820 KiB
16Runtime error0/42ms3752 KiB
17Runtime error0/42ms3772 KiB