We have contest, that contains two parts.
Part 1. Knockout until we have an odd number of players. In each round players are paired up; each pair plays a game with the winning player advancing to the next round (no ties). This part continues as long as number of players is even. When we come to round with are an odd number of players we go to part 2.
- Part 1 will be skipped, if starting quantity of players is odd
- If Part 1 ends with 1 player then contest is considered over, we got a winner
Part 2. Round-robin. Each participant plays every other participant once. The player with the most points is the winner.
How many players must be invited to participate in the contest for got N games to be played?
Here can be multiple correct numbers of players (2?).
Example 1. We need a contest with 3 games. We can invite 3 players, than contest start with part 2 and 3 games will played. Or we can invite 4 players and part 1 will be made with 3 games too. 2 semi-finals, final and we got a winner.
Example 2. We need contest with 12 games. We must invite 12 players. Contest start with Part 1, where will be played $6 + 3$ games, than 3 more games will be played in Part 2. So the got $6 + 3 + 3 = 12$ games.
My thoughts.
We have 3 variants of contest.
Part 1 only. Number of players must be power of 2, then will be played $N - 1$ games. It's can be easily checked, just add 1 to N and take Log2, if result is not fractional than we got an answer.
Part 2 only. Number of players must be a "triangular number". It's a little bit harder. Such quantity of players will be play $N * (N +1) / 2$ amount games. Possible amount of players for N games: $\frac{\sqrt{8 \times N + 1} + 1}{2}$. Again if result is not fractional than we got an answer.
Most difficult variant. We have both parts, and no idea about players count. What can we understand from all of this...
number of players in part 2 minimum is 3
number of players in part 2 maximum = 1/2 part 1 minimum
maximal count of games in part 2 = N - num of Part 1 games
- For example, we need 946 games, then we invite 86 players, wich will play 43 games in Part 1 and 903 games in Part 2.
maximal count of games in part 1 = N - 3
- For 768 games we need invite 768 players, wich will play 765 games in Part 1 and 3 games in Part 2.
number of games in part 1 always is odd
number of players in part 2 less that number of players in part 1 in "power of 2" times (2,4,8,16...)
My naive solution for variant #3.
Start from 3 and increase number of players in part 2 until count of games in part 2 less than N - part 2 players. Check all possible counts. It's work, but for N = 10^18 amount of iterations ~ 10^9, that looks not efficient.