fb pixel

Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms

  • The most significant bit

    Given an integer n, you are asked to calculate its most significant bit and print the corresponding power of 2.

    Input

    The input contains a single integer n (1 ≤ n ≤ ).

    Output

    The program should print the index of the most significant bit and the corresponding power of 2 separated by a space. The indexing starts at 0.

    Examples

    Input
    Output
    9
    3 8
    311
    8 256

    Explanation

    • 9 → 1001 ⇒ the index is 3 and the power of 2 is 8
    • 311 → 100110111 ⇒ the index is 8 and the power of 2 is 256
     
    To check your solution you need to sign in
    Sign in to continue