We look at the more general situation and set the number to M
Then n < m * 2 no solution
Then n is an odd number of cases:
We packed a person and a space, and left M "people" and n-m spaces, randomly arranging the "people", then inserting the blanks
The nature of the different "people" is arranged in the circumference (m-1)! For each arrangement, there are m positions inserted into n-m spaces, there are methods in C (N-m-1, m-1), and for an arrangement, the circumference is arranged with n
Ans = C (n-m-1, m-1) * (M-1)! * N
Finally, N is an odd number of cases:
We pack the opposite two points and then turn into a circle of length N/2
Equivalent to N/2 selected M, a continuous K-segment 1 scheme corresponding to the original 2k scheme
So ans = n/2 * (m-1)! *σ (2k * C (N/2-m-1, k-1) * C (M, K)) (where 1≤k≤m)
Then the topic compares the ghost animal ... I'd better be on the py ...
1 defC (N, m):2 if(N < m):return03 returnFac[n]/fac[m]/fac[n-m]4 5 defwork_odd (N, m):6 returnn * C (N-M-1, m-1) * fac[m-1]7 8 defWork_even (N, m):9res =0TenN/= 2 Onei =m A while(I >0): -Res = (res + c (n-m-1, i-1) * C (M, i)) * 2 -I-= 1 the returnRES * FAC[M-1] *N; - -FAC = [1] * 105 - forIinchRange (1, max): fac[i] = fac[i-1] *I +n =input () -m = 8 + while(N >0): A if(N < M * 2):Print0 at elif(n% 2 = = 1):Printwork_odd (n, m) - Else:PrintWork_even (n, m) -n = input ();
View Code
AOJ2025 Eight Princes