P21706 [GeeksforGeeks] First and last bit2357
普及-
题目描述

Given a positive integer n. The problem is to check whether only the first and last bits are set in the binary representation of n. The answer is 1 if the first and last bit is set else 0.
Example 1:
Input: N = 9
Output: 1
Explanation: (9){10} = (1001), only
the first and last bits are set.
​Example 2:
Input: N = 15
Output: 0
Explanation: (15){10} = (1111), except
first and last there are other bits also
which are set.
Your Task:
Your task is to complete the function onlyFirstAndLastAreSet() which takes the N as inputs and returns the answer.
Expected Time Complexity: O(log N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{9}

输入格式

见题面

输出格式

见题面

样例输入
N = 9
样例输出
1