Remove Rightmost Set Bit
Python
Medium
7 views
Problem Description
One non-negative integer n is provided (n>0). Remove the rightmost set bit once and output the new number.
Input Format
One integer n.
Output Format
One integer.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
sys.stdout.write(str(n & (n-1)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!