Description

A △△ game competition is now being held. In this competition, N players participate and the game proceeds as a tournament. N participants are given a number from 1 through N. Then, participants of number 1↔number 2, number 3↔number 4, ... , number N-1↔number N play a game. The winner of each match proceeds to the next round. The participants to move on to the next round will receive a new number from 1 through N/2. If participant number 2 wins in the game between participant number 1↔participant number 2, the number 1 is given. Similarly, if participant number 3 wins in the game between participant number 3↔participant number 4, the number 2 is given. The competition will continue until the last participant remains.

In the first round, a participant number A wonders which round he will play with the participant number B, who is regarded as his rival. Given the number of participants N, the first number given to participant A, and the first number given to participant B as parameters, write a function solution to return which round participant number A will play a game with his rival, participant number B. Assume that participants number A and B will always win until they meet.

Constraints
  • N : a natural number between 21 and 220 (Since it is given as an exponential of 2, there are no default wins).
  • A, B : natural number less than or equal to N (However, A ≠ B).

Examples
N A B answer
8 4 7 3

Example #1
In the first round, participant number 4 plays a game with participant number 3 and participant number 7 plays a game with participant number 8. Since we assume that participant number 4 and number 7 always wins, participant number 4 and number 7 receive number 2 and number 4 at the next round, respectively. In the second round, participant number 2 plays a game with participant number 1 and participant number 4 plays a game with participant number 3. Similarly, participant number 2 and number 4 is given the number 1 and 2 in the next round, respectively. Since these participants play a game as participant number 1 and number 2 in the third round, return 3.

Result Stop
Result of [Run Test] or [Submit] will be displayed here
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.