Enumeration of Tournaments
Time limit1sMemory limit256 MB
Given n players in a single-elimination bracket with random pairings each round, count the distinct possible tournaments modulo 2^64 for n up to 10^18.
- Level
Hard8 of 10
- Topics
- Combinatorics, Recursion, Math
- Solved
- No attempts yet
Problem
Suppose that players participate in a single-elimination tournament. The tournament goes round by round. Let be the number of remaining players at the beginning of a round. The players then form random pairs, and every possible partition into pairs is equally likely. In each pair, the two players play one game, the one with the higher rating wins, and the loser leaves the tournament. The remaining players advance to the next round.
Each participant has a unique rating, and the result of each game is fully determined by the ratings: the player with the higher rating always wins. The only thing that affects the schedule of the tournament is the random pairing made in each round. Count the number of different tournaments that could occur. Two tournaments are different if some game between two participants occurs in one of them but not in the other.
The answer can be large, so output it modulo .
Input
The input contains one integer , the initial number of players ().
Output
Output the number of different tournaments modulo .