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
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation

  • 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
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue