#C7960. Arrange the Matches
Arrange the Matches
Arrange the Matches
You are given an integer n
representing the number of employees. The task is to determine how many different ways there are to arrange the matches (i.e. pair up the employees) if every employee is to be paired with exactly one other employee.
If n
is odd, then it is impossible to pair everyone and the answer should be 0
. For even n
, the result is given by the formula:
\(\frac{n!}{2^{n/2}(n/2)!} \pmod{10^9+7}\)
For example:
- For
n = 4
: the answer is3
. - For
n = 6
: the answer is15
. - For odd numbers (e.g.,
n = 1, 3, 5
): the answer is0
.
Write a program that reads an integer from standard input and prints the number of ways to arrange the matches modulo \(10^9+7\) to standard output.
inputFormat
The input consists of a single integer n
on one line, representing the number of employees.
outputFormat
Output a single integer representing the number of different ways to arrange the matches modulo \(10^9+7\). If n
is odd, output 0
.
4
3