\\ PARI code for A343867 \\ The following program is only suitable for Latin squares of prime order. \\ Since only odd orders that are not divisible by 3 have solutions, the first difficult case is for order 25 (n=12). \\ Enumerates all solutions of the n-queens problem on a n X n toroidal board with a queen in the (0,0) cell. \\ The number of solutions is A071607. \\ Each solution is passed to the user defined function f and the sum of the ouputs from that function returned. \\ This method is not particularly efficient. Queens(n, f(v)=1)={ local(v=vector(n)); my(recurse(k, S, d1, d2)=if(k==n, f(v), sum(j=1, n-1, if(!bittest(S,j) && !bittest(d1, (j-k)%n) && !bittest(d2, (j+k)%n), v[1+k]=j; self()(1+k, S+(1< d, return(0))); 1} \\ Test for a semi-cyclic square with step (1,d). \\ With squares which are not of prime order there may also be steps that are not of this form. IsSemi(v, d) = {my(n=#v, b=0); for(i=0, n-1, my(j=(v[i+1]-d*i)%n); if(bittest(b, j), return(0)); b=bitor(b, 1<