16042022-11-28 20:37:00kicsiboglarAutókódoláscpp11Futási hiba 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base0/50
1Futási hiba0/03ms1976 KiB
2Futási hiba0/02ms2168 KiB
3Futási hiba0/22ms2368 KiB
4Futási hiba0/23ms2924 KiB
5Futási hiba0/22ms2988 KiB
6Futási hiba0/22ms3176 KiB
7Futási hiba0/22ms3164 KiB
8Futási hiba0/42ms3364 KiB
9Futási hiba0/42ms3644 KiB
10Futási hiba0/42ms3988 KiB
11Futási hiba0/42ms3760 KiB
12Futási hiba0/42ms3564 KiB
13Futási hiba0/42ms3840 KiB
14Futási hiba0/42ms3884 KiB
15Futási hiba0/42ms3820 KiB
16Futási hiba0/42ms3752 KiB
17Futási hiba0/42ms3772 KiB