
EXAMPLE

a(1) = 1 due to the circular permutation (0,1).
a(2) = 0 since 2*2^2+1 is composite.
a(3) = 1 due to the circular permutation (0,1,2,3).
a(4) = 0 since 2*(4^2k^2)+1 is composite for any k = 0,2,3.
a(5) = 1 due to the circular permutation (0,1,4,5,2,3).
a(6) = 6 due to the circular permutations
(0,1,3,2,5,4,6), (0,1,4,6,5,2,3), (0,1,6,4,5,2,3),
(0,3,1,2,5,4,6), (0,3,2,1,4,5,6), (0,3,2,5,4,1,6).
a(7) = 3 due to the circular permutations
(0,1,7,4,6,5,2,3), (0,3,2,1,7,4,5,6), (0,3,2,5,4,7,1,6).
a(8) = 16 due to the circular permutations
(0,1,3,2,5,8,7,4,6), (0,1,6,4,7,8,5,2,3),
(0,1,7,8,4,6,5,2,3), (0,1,8,7,4,6,5,2,4),
(0,3,1,2,5,8,7,4,6), (0,3,2,1,4,7,8,5,6),
(0,3,2,1,7,4,8,5,6), (0,3,2,1,7,8,4,5,6),
(0,3,2,1,7,8,5,4,6), (0,3,2,1,8,7,4,5,6),
(0,3,2,5,4,7,8,1,6), (0,3,2,5,4,8,7,1,6),
(0,3,2,5,8,1,7,4,6), (0,3,2,5,8,4,7,1,6),
(0,3,2,5,8,7,1,4,6), (0,3,2,5,8,7,4,1,6).
a(9) > 0 due to the permutation (0,3,2,1,6,4,7,8,5,9).
a(10) > 0 due to the permutation (0,9,5,6,4,7,8,10,2,3,1).


MATHEMATICA

(* A program to compute required circular permutations for n = 7. To get "undirected" circular permutations, we should identify a circular permutation with the one of the opposite direction; for example, (0, 6, 1, 7, 4, 5, 2, 3) is identical to (0, 3, 2, 5, 4, 7, 1, 6) if we ignore direction. Thus a(7) is half of the number of circular permutations yielded by this program. *)
p[i_, j_]:=PrimeQ[2*Abs[i^2j^2]+1]
V[i_]:=Part[Permutations[{1, 2, 3, 4, 5, 6, 7}], i]
m=0
Do[Do[If[p[If[j==0, 0, Part[V[i], j]], If[j<7, Part[V[i], j+1], 0]]==False, Goto[aa]], {j, 0, 7}]; m=m+1; Print[m, ":", " ", 0, " ", Part[V[i], 1], " ", Part[V[i], 2], " ", Part[V[i], 3], " ", Part[V[i], 4], " ", Part[V[i], 5], " ", Part[V[i], 6], " ", Part[V[i], 7]]; Label[aa]; Continue, {i, 1, 7!}]
