Loading Now

Easy Number Game

After a long rest, Van back to work. When he came to the office, near the door he saw Hoa and her boss – Mr.Viet were playing a mini game with simple rule: each player chooses a number in the range from 1 to n. Let’s assume that Hoa chose number h, and Viet chose number vBy using a random generator they choose a random number x between 1 and n (any number is chosen with the same probability) and the winner is the player, whose number was closer to x.

Hoa agreed that if v and h are located on the same distance from x, Mr.Viet wins. But Van wants Hoa to win very much, so he asks you to help him. You know the number selected by Viet, and number n. You need to determine which value of h that Hoa must choose, so that the probability of her victory is the highest possible. For clearly, you need to find number h, that the probability that |h - x| < |v - x| is maximal (1 ≤ h, x ≤ n). It’s guaranteed that each time Van by some way, said to Hoa, Mr.Viet could not hear anything.

Example

  • For n = 3, v = 1, the output should be easyNumberGame(n,v) = 2.
  • For n = 4, v = 3, the output should be easyNumberGame(n,v) = 2.

Input/Output

  • [execution time limit] 0.5s (C++), 1s (Java, C#), 1s (Js, Python, Go)

  • [Input] integers v, n

    1 ≤ v ≤ n ≤ 10^12.

  • [Output] integer H:
    Print out value of H, that probability that Hoa wins is the highest. If there are multiple such values, print the minimum of them.

Post Comment

Contact