21192022-12-20 12:35:301478Autókódoláscpp11Partially correct 48/503ms4252 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 || ans1 == n) cout<<-1<<'\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 == 0 || tempN%2 == 1 && (tempN/2)%2 == 0){
        ///aktualis bit
            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<<'\n';





    return 0;
}
SubtaskSumTestVerdictTimeMemory
base48/50
1Accepted0/03ms1880 KiB
2Accepted0/02ms2068 KiB
3Accepted2/22ms2144 KiB
4Accepted2/22ms2276 KiB
5Partially correct1/22ms2488 KiB
6Partially correct1/22ms2704 KiB
7Accepted2/22ms2760 KiB
8Accepted4/42ms2968 KiB
9Accepted4/42ms3164 KiB
10Accepted4/42ms3296 KiB
11Accepted4/42ms3508 KiB
12Accepted4/42ms3620 KiB
13Accepted4/42ms3828 KiB
14Accepted4/42ms4020 KiB
15Accepted4/42ms4252 KiB
16Accepted4/42ms4108 KiB
17Accepted4/42ms4240 KiB