Building Bridge to Srilanka

0

0 votes
maths
Problem

There is a stone bridge connecting India to Srilanka. First stone starting from India is having 1 inscribed on it, and last stone is on Srilankan side. Each subsequent stone has two consecutive numbers on it except the last stone which may have one or two numbers inscribed on it depending on value of N. Stones may be aligned as: 1, (2, 3), (4, 5), (6, 7)... N.

 

You are given a number N representing the last number on the last stone; and a number X. The task is to find the minimum number of jumps you need from either Indian side or Srilankan side to reach the stone that has X inscribed on it.

Note: Jumping on first stone will be counted as 0 jumps.

 

Input format:

  • The input contains just one line of two space-separated integers N and X respectively

Output format:

  • Output just one integer i.e. minimum jumps needed to reach X from either side India or Srilanka.
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation
Explanation 
here N=10, and X=3.
Stone alignment for N = 10 is as follows:
1, (2, 3), (4, 5), (6, 7), (8, 9), 10
To jump on X = 3, you only need one jump (since first stone jump will not be counted) 
from India side, and 4 jumps from Srilanka side. So the minimum of 1 and 4 is 1.

 

 

Editor Image

?