CF Round 468 -- B. World Cup

The last stage of Football World Cup is played using the play-off system.

There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.

Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.

Input

The only line contains three integers na and b (2 ≤ n ≤ 256, 1 ≤ a, b ≤ n) — the total number of teams, and the ids of the teams that Arkady is interested in.

It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.

Output

In the only line print "Final!" (without quotes), if teams a and b can meet in the Final.

Otherwise, print a single integer — the number of the round in which teams a and b can meet. The round are enumerated from 1.

input

4 1 2

output

1

input

8 2 6

output

Final!

input

8 7 5

output

2

Note

In the first example teams 1 and 2 meet in the first round.

In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.

In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.

题意:有n个队伍,每次都是第 i 和第 i+1 比赛,胜利者晋级,a和b是两个队伍的初始编号,问a和b最终会在第几轮比赛相遇,如果是最后一轮比赛输出Final!,保证a和b每次都会获胜,每次都是两两对决。

解析:对于第 i 个队伍,他将会被安排在第 \left \lceil \frac{i}{2} \right \rceil组中,然后胜利之后也就下标也就变成了\left \lceil \frac{i}{2} \right \rceil,然后我们计数当前轮数,如果ab在同一个组中了,那么代表相遇,判断是否是最后一轮,输出轮数即可。

#include 
using namespace std;
void solve()
{
    int n,a,b,m=0;//m记录n个队伍最多有几场比赛
    scanf("%d%d%d",&n,&a,&b);
    while(n>=2) m++,n/=2;
    int k=1;//记录当前进行的轮数
    a=(a-1)/2+1,b=(b-1)/2+1;//ab最初在哪一组
    while(a!=b)
    {
        a=(a-1)/2+1;
        b=(b-1)/2+1;
        k++;//轮数++
    }
    if(k==m) printf("Final!\n");//如果为总决赛
    else printf("%d\n",k);
}
int main()
{
    int t=1;
    //scanf("%d",&t);
    while(t--) solve();
    return 0;
}

你可能感兴趣的:(c++,c语言)