Unlike seating in a row, a round table has no fixed starting point. Therefore, all arrangements that differ only by a cyclic shift are considered the same.
If the people were seated in a row, the number of possible arrangements would be , since distinct people can be permuted arbitrarily.
For a round table, each specific seating can be rotated in different ways, producing equivalent linear permutations.
For example, for the seating (1, 2, 3, 4), the rotations give:
All these seatings are considered the same.
Therefore, each unique circular arrangement corresponds to exactly linear permutations.
To obtain the number of distinct seatings around a round table, the total number of permutations must be divided by the number of equivalent rotations:
Example
For people, there are distinct arrangements:
(1, 2, 3, 4)
(1, 2, 4, 3)
(1, 3, 2, 4)
(1, 3, 4, 2)
(1, 4, 2, 3)
(1, 4, 3, 2)
All other arrangements can be reduced to one of the listed ones by rotation. For example, the arrangement (4, 2, 1, 3) is equivalent to (1, 3, 4, 2).
Algorithm implementation
Read the input value of .
scanf("%lld", &n);The answer is computed in the variable .
res = 1;
for (i = 1; i < n; i++)
res = res * i;Print the answer.
printf("%lld\n", res);