%I #24 Jan 22 2022 08:47:10
%S 1,2,2,16,16,192,192,6912,4608,230400,230400,11612160,11612160,
%T 1199923200,588349440,98594979840,98594979840,11076328488960,
%U 11076328488960,2102897147904000,1076597725593600,331238941183180800,331238941183180800,66325953940291584000,56326771107377971200
%N a(n) is number of permutations (p(1),p(2),p(3),...,p(n)) of (1,2,3,...,n) such that p(k) is coprime to p(n+1-k) for k = all positive integers <= n.
%C For n = odd integer the middle term of all counted permutations must be 1.
%C From _Robert Israel_, Sep 12 2016: (Start)
%C Consider the graph with vertices [1,...,n] if n is even, [2,...,n] if n is odd, and edges joining coprime integers.
%C a(n) is A037223(n) times the number of perfect matchings in this graph.
%C If n is even, a(n) = A037223(n)*A009679(n/2).
%C If n is an odd prime, a(n) = a(n-1). (End)
%H Robert Israel, <a href="/A133922/b133922.txt">Table of n, a(n) for n = 1..31</a>
%e For n = 6, the permutation (3,2,1,6,4,5) is not counted because p(2)=2 is not coprime to p(5)=4. However, the permutation (3,6,1,4,5,2) is counted because GCD(3,2) = GCD(6,5) = GCD(1,4) = 1.
%p M:= proc(A) option remember;
%p local n,t,i,Ai,Ap,inds,isrt,As;
%p n:= nops(A);
%p if n = 0 then return 1 fi;
%p t:= 0;
%p for i in A[1] do
%p inds:= [$2..i-1,$i+1..n];
%p Ai:= subs([1=NULL,i=NULL,seq(inds[i]=i,i=1..n-2)],A[inds]);
%p isrt:= sort([$1..n-2],(r,s) -> nops(Ai(r)) <= nops(Ai(s)),output=permutation);
%p Ai:= subs([seq(isrt[i]=i,i=1..n-2)],Ai[isrt]);
%p t:= t + procname(Ai);
%p od;
%p t;
%p end proc:
%p F:= proc(n) local A;
%p if n::odd then
%p if isprime(n) then return procname(n-1) fi;
%p A:= [seq(select(t -> igcd(t+1,i+1)=1, [$1..i-1,$i+1..n-1]),i=1..n-1)];
%p else
%p A:= [seq(select(t -> igcd(t,i)=1,[$1..i-1,$i+1..n]),i=1..n)]
%p fi;
%p M(A)*floor(n/2)!*2^floor(n/2)
%p end proc;
%p seq(F(n),n=1..27); # _Robert Israel_, Sep 12 2016
%Y Cf. A009679, A081123, A037223.
%K hard,nonn
%O 1,2
%A _Leroy Quet_, Jan 07 2008
%E a(6)-a(15) from _Sean A. Irvine_, May 17 2010
%E a(16)-a(25) from _Robert Israel_, Sep 12 2016