175782025-07-26 10:25:53KristófAutókódoláscpp17Wrong answer 1/501ms548 KiB
#include <iostream>
#include <cmath>

using namespace std;

void printbinary(long long a)
{
int n=(int)log2(a);
    if(pow(2,(int)log2(a))!=a)
        {
        n++;
        }
cout<<n<<" " ;
for(int i=n-1;i>-1;i--)
    {
    if(a &(1<<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=(int)log2(a);
    if(pow(2,(int)log2(a))!=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 & (1<<j)))
                {
                b=true;
                continue;
                }
            else
                {
                if(b)
                    {
                    tmp1=((1*1LL)<<(j));
                    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 & (1<<i))
            {
            if(b==false)
                {
                tmp=i;
                }
            b=true;
            oc++;
            }
        else
            {
            if(b)
                {
                break;
                }
            }

        }
    //cout<<((1*1LL)<<tmp+1)<<" ";
    cout<<a+((1*1LL)<<tmp+1)+(pow(2,oc-1)-1);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Wrong answer0/01ms512 KiB
2Wrong answer0/01ms316 KiB
3Partially correct1/21ms316 KiB
4Wrong answer0/21ms508 KiB
5Wrong answer0/21ms508 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/41ms548 KiB
9Wrong answer0/41ms316 KiB
10Wrong answer0/41ms316 KiB
11Wrong answer0/41ms316 KiB
12Wrong answer0/41ms508 KiB
13Wrong answer0/41ms316 KiB
14Wrong answer0/41ms316 KiB
15Wrong answer0/41ms316 KiB
16Wrong answer0/41ms316 KiB
17Wrong answer0/41ms316 KiB