A router derives a shared subnet mask by taking the bitwise AND of every address in a contiguous block. Given the block endpoints L and R, compute the bitwise AND of all integers from L to R inclusive.
Line 1: two space-separated integers L and R.
A single integer: L & (L+1) & ... & R.
Example 1
Input
5 7
Expected
4
Explanation
5=101, 6=110, 7=111; their AND is 100 = 4 (only the common leading bit survives).
Example 2
Input
12 15
Expected
12
Explanation
12=1100, 13=1101, 14=1110, 15=1111; their AND is 1100 = 12.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →