175802025-07-26 11:00:50KristófAutókódoláscpp17Partially correct 48/501ms508 KiB
#include <iostream>
#include <cmath>

using namespace std;

void printbinary(long long a)
{
int n=(int)log2(a)+1;
    if(pow(2,(int)log2(a))!=a)
        {
        n++;
        }
cout<<(1LL<<(n-1))<<" "<<a<<" " ;
for(int i=n-1;i>-1;i--)
    {
    if(a &(1LL<<i))
        {
        cout<<1;
        }
    else
        {
        cout<<0;
        }
    }
cout<<"\n";
}


int main()
{
    long long a;
    long long tmp1;
    //long long mina,maxa;
    cin>>a;
    //printbinary(a);
    int n=0;
    while((1LL<<n) <=a) n++;
    //cout<<n;
    if((int)log2(a)!=(int)log2(a+1))
        {
        cout<<"-1\n";
        }
    else
        {
        bool b=false;
        for(long long j=0;j<=n;j++)
            {
            if(!(a & (1LL<<j)))
                {
                b=true;
                //continue;
                }
            else
                {
                if(b)
                    {
                    tmp1=(1LL<<(j-1));
                    //cout<<0+pow(2,j-1)<<endl;
                    //printbinary(tmp1);
                    cout<<a-tmp1<<endl;
                    //printbinary(a-tmp1);//<<"\n";
                    break;
                    }
                }
            }
        }
    int oc=0;
    bool b=false;
    int tmp;
    for(int i=0;i<=n;i++)
        {
        if(a & (1LL<<i))
            {
            if(b==false)
                {
                tmp=i;
                }
            b=true;
            oc++;
            }
        else
            {
            if(b)
                {
                break;
                }
            }

        }
    //cout<<((1*1LL)<<tmp+1)<<" ";
    //printbinary(a+((1*1LL)<<tmp+1)+(pow(2,oc-1)-1));
    cout<<a+((1*1LL)<<tmp)+((1LL<<(oc-1))-1);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base48/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Partially correct1/21ms316 KiB
6Partially correct1/21ms508 KiB
7Accepted2/21ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/41ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/41ms316 KiB
13Accepted4/41ms364 KiB
14Accepted4/41ms328 KiB
15Accepted4/41ms352 KiB
16Accepted4/41ms500 KiB
17Accepted4/41ms316 KiB