Editorial
First, we should select people for the first circle dance. This can be done in 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 people can be arranged in any order, namely 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 , the divisions into circle dances and are considered the same.
Simplifying the given formula, we get the answer:
Example
For example, for the number of ways is :
One round dance — , another — ;
One round dance — , another — ;
One round dance — , another — .
According to the formula for , the answer is
Let's construct all distinguishable circle dances for . 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 circle dances with participants. However, the number of distinguishable circle dances for is .
Algorithm realization
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 realization
The fact function computes the factorial of the number .
def fact(n): res = 1 for i in range(2, n + 1): res *= i return res
The 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)