Count of Matches in Tournament
You are given an integer n, the number of teams in a tournament that has strange rules:
- If the current number of teams is even, each team gets paired with another team. A total of
n / 2matches are played, andn / 2teams advance to the next round. - If the current number of teams is odd, one team randomly advances in the tournament, and the rest gets paired. A total of
(n - 1) / 2matches are played, and(n - 1) / 2 + 1teams advance to the next round.
Return the number of matches played in the tournament until a winner is decided.
Example 1
Input
n = 7Output
6The rounds have 3, 2, and 1 matches respectively, for a total of 6 matches.
Example 2
Input
n = 14Output
13The rounds have 7, 3, 2, and 1 matches respectively, for a total of 13 matches.
Constraints
- 1 <= n <= 200