21172022-12-20 12:25:551478Autókódoláscpp11Partially correct 45/503ms4024 KiB
#include <bits/stdc++.h>

using namespace std;


int main()
{
    //ifstream cin("be.txt");
    long long n;
    cin>>n;

    long long tempN = n;
    long long multTwo = 1;

    ///kisebb
    long long ans1 = 0;
    while(tempN > 0){
        ans1 += multTwo * (tempN%2);
        if(tempN%2 == 0 && tempN/2 > 0 && (tempN/2)%2 == 1){
        ///aktualis bit
           ans1 += multTwo;
        ///maradek
           tempN/=4;
           ans1 += tempN*4*multTwo;
           break;
        }
        multTwo *= 2;
        tempN /= 2;
    }

    if(ans1 == 1) cout<<-1<<'\n';
    else if(ans1 == n) cout<<ans1/2<<'\n';
    else cout<<ans1<<'\n';

    ///nagyobb
    tempN = n;
    multTwo = 1;
    int numberOfZerosAtEnd = 0;
    while(tempN > 0 && tempN%2 == 0){
        numberOfZerosAtEnd++;
        multTwo *= 2;
        tempN /= 2;
    }
    //cout<<numberOfZerosAtEnd<<'\n';
    long long ans2 = 0;
    while(tempN > 0){
        if(tempN%2 == 1 && tempN/2 == 0 || (tempN/2)%2 == 0){
        ///aktualis bit
            //cout<<ans2<<'\n';
            while(numberOfZerosAtEnd){
                ans2/=2;
                numberOfZerosAtEnd--;
            }

            ans2 += multTwo*2;

        ///maradek
           tempN/=4;
           ans2 += tempN*4*multTwo;
           break;
        }
        else{
            ans2 += multTwo * (tempN%2);
        }

        multTwo *= 2;
        tempN /= 2;
    }
    cout<<ans2;





    return 0;
}
SubtaskSumTestVerdictTimeMemory
base45/50
1Accepted0/03ms1876 KiB
2Accepted0/02ms2064 KiB
3Partially correct1/22ms2172 KiB
4Accepted2/22ms2376 KiB
5Partially correct1/22ms2600 KiB
6Partially correct1/22ms2716 KiB
7Accepted2/22ms2792 KiB
8Accepted4/42ms2924 KiB
9Accepted4/42ms3120 KiB
10Accepted4/42ms3204 KiB
11Accepted4/42ms3348 KiB
12Accepted4/42ms3432 KiB
13Partially correct2/42ms3540 KiB
14Accepted4/42ms3796 KiB
15Accepted4/42ms3876 KiB
16Accepted4/42ms4024 KiB
17Accepted4/42ms3976 KiB