First, we should select people for the first circle dance. This can be done in C^{n/2}_n ways. Let's count the number of ways to arrange people within one circle dance. Fix the person who will be first, after which the remaining n / 2 - 1 people can be arranged in any order, namely (n / 2 - 1)! ways. The number of ways to form two circle dances is:
The division by is necessary so that we do not distinguish between pairs of circle dances and . For example, for n = 4, the divisions into circle dances ([1, 2], [3, 4]) and ([3, 4], [1, 2]) are considered the same.
Simplifying the given formula, we get the answer:
Example
For example, for n = 4 the number of ways is :
One round dance — , another — ;
One round dance — , another — ;
One round dance — , another — .
According to the formula for n = 4, the answer is
Let's construct all distinguishable circle dances for n = 4. We place participant in the first position. In the remaining three positions, any permutation of the other three participants can be placed.
By rotating any of these arrangements in a circle, we can obtain indistinguishable circle dances. For example, the following arrangements are indistinguishable (consider the cyclic shifts of the last permutation):
There are 4! = 24 circle dances with participants. However, the number of distinguishable circle dances for n = 4 is 3! = 6.
Algorithm implementation
The fact function computes the factorial of the number .
long long fact(int n)
{
long long res = 1;
for (int i = 2; i <= n; i++)
res *= i;
return res;
}The main part of the program. Read the input value of .
scanf("%d", &n);Compute and print the result.
res = 2 * fact(n - 1) / n;
printf("%lld\n", res);Python implementation
The fact function computes the factorial of the number .
def fact(n):
res = 1
for i in range(2, n + 1):
res *= i
return resThe main part of the program. Read the input value of .
n = int(input())Compute and print the result.
res = 2 * fact(n - 1) // n
print(res)