Remark: $C_6$ has $6!/2$ Eulerian orderings, and $C_{10}$ has $10!/3$ ones (see computation below).
# %attach SAGE/IntegerOrder.spyx
from sage.all import *
cpdef IsEulerianOrdering(int n, list L): # It checks whether L is a (partial) Eulerian ordering.
cdef int i,j,k,s1,s2,s3,a,b,c,g1,g2,p
for s1 in range(1,len(L)):
i=L[s1]
for s2 in range(s1):
j=L[s2]
for s3 in range(s1):
c=0
k=L[s3]
g1=gcd(n,i-k)
g2=gcd(n,i-j)
p=n/g1
if is_prime(p) and g1 % g2 == 0:
c=1
break
if c==0:
print([i,j])
return False
return True
cpdef IntegerOrder(int n, list LL): # If LL is not a partial Eulerian ordering, then it return False. Else it try to complete LL lexicographically (possibly return a partial Eulerian ordering).
cdef int t,s,i,j,k,a,b,c,g1,g2,p,l
cdef list L,T
if IsEulerianOrdering(n,LL):
T=range(n)
l=len(LL)
L=LL
for t in LL:
T.remove(t)
for s in range(n-l):
c=0
for i in T:
a=0
for j in L:
b=0
for k in L:
g1=gcd(n,i-k)
g2=gcd(n,i-j)
p=n/g1
if is_prime(p) and g1 % g2 ==0:
b=1
break
if b==0:
a=1
break
if a==0:
L.append(i)
T.remove(i)
c=1
break
if c==0:
break
return L
return False
cpdef TestSquareFree(int r1, int r2):
cdef int n,l
cdef list L
for n in range(r1,r2+1):
if is_squarefree(n) and not is_prime(n):
L=IntegerOrder(n,[0])
l=len(L)
if l<n:
return n
return True
cpdef MixedBase(int n, list s):
cdef int l, m, i, c
cdef list b,
l=len(s)
b=[]
m=n
for i in range(l):
c=m//s[i]
b.append(m-s[i]*c)
m=c
return b
cpdef MixedBaseOrdering(list s):
cdef list b,o
cdef int p,l,i,n,m
n=prod(s)
o=[]
for r in range(n):
b=MixedBase(r,s)
l=len(s)
m=sum([b[i]*n/s[i] for i in range(l)]) % n
o.append(m)
return o
cpdef HowManyEulerianOrdering(int n):
cdef list L
cdef int r
L=Permutations(range(n)).list()
r=0
for l in L:
if IsEulerianOrdering(n,list(l)):
r+=1
return r
sage: IntegerOrder(22,[0])
[0, 2, 4, 6, 8, 10, 11, 1, 3, 5, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
sage: IntegerOrder(210,[0])
[0, 30, 42, 12, 54, 24, 60, 18, 48, 6, 36, 66, 70, 72, 2, 78, 84, 90, 96, 100, 102, 32, 105, 108, 112, 82, 40, 114, 44, 14, 74, 120, 15, 124, 4, 88, 28, 58, 94, 10, 52, 98, 8, 38, 50, 20, 62, 80, 92, 22, 64, 104, 34, 76, 16, 46, 86, 26, 56, 68, 106, 110, 116, 118, 122, 126, 21, 111, 128, 130, 132, 27, 117, 134, 135, 9, 129, 3, 123, 136, 138, 33, 140, 35, 141, 1, 142, 144, 39, 146, 147, 148, 150, 45, 152, 153, 154, 155, 156, 51, 121, 158, 159, 160, 161, 41, 71, 125, 162, 57, 127, 7, 37, 91, 164, 165, 166, 167, 47, 5, 75, 77, 107, 65, 131, 61, 19, 49, 79, 109, 25, 55, 13, 43, 85, 97, 103, 113, 23, 53, 11, 81, 83, 93, 95, 115, 31, 73, 119, 29, 59, 17, 87, 89, 99, 101, 133, 63, 137, 67, 139, 69, 143, 145, 149, 151, 157, 163, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209]
sage: TestSquareFree(2,500)
True
sage: HowManyEulerianOrdering(6)
360
sage: HowManyEulerianOrdering(10)
1209600