1 solutions

  • 1
    @ 2023-10-25 20:05:15
    #include<iostream>
    using namespace std;
    
    int main(){
        int D = 1;
        int K;
        cin >> K;
        while(D < K){
            D *= 2;
        }
        if(D == K){
            cout << D << ' ' << 0 << endl;
        }else{
            int len = D/2;
        
            int l = len;
            int r = D;
            int cnt = 0;
            while(l < r){
                cnt++;
                len /=2;
                if((l == K) || (r == K)){
                    cout << D << ' ' << cnt << endl;
                    break;
                }
                else if((l + len) > K){
                    r = r - len;
                }
                else{
                    l = l + len;
                }
            }
        }
        return 0;
    }
    
    • 1

    Information

    ID
    6587
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    # Submissions
    26
    Accepted
    8
    Uploaded By