login
A213890
For any n >= 0, write all permutations of {0,1,...,n} in reverse lexicographic order. The last elements of the permutations will be the initial terms of this sequence.
1
0, 1, 0, 2, 1, 2, 0, 1, 0, 3, 1, 3, 0, 2, 0, 3, 2, 3, 1, 2, 1, 3, 2, 3, 0, 1, 0, 2, 1, 2, 0, 1, 0, 4, 1, 4, 0, 2, 0, 4, 2, 4, 1, 2, 1, 4, 2, 4, 0, 1, 0, 3, 1, 3, 0, 1, 0, 4, 1, 4, 0, 3, 0, 4, 3, 4, 1, 3, 1, 4, 3, 4, 0, 2, 0, 3, 2, 3, 0, 2, 0, 4, 2, 4, 0, 3, 0, 4, 3, 4, 2, 3, 2, 4, 3, 4, 1, 2, 1, 3, 2, 3, 1, 2, 1, 4, 2, 4, 1, 3, 1, 4, 3, 4, 2, 3, 2, 4, 3, 4, 0, 1, 0, 2, 1, 2, 0, 1, 0, 3
OFFSET
0,4
COMMENTS
a(A007489(n)) = n is the first occurrence of n in the sequence.
LINKS
David W. Wilson, C++ function to efficiently compute a(n).
EXAMPLE
For n = 2, the permutations of {0,1,2} in reverse lexical order are: (2,1,0),(2,0,1),(1,2,0),(1,0,2),(0,2,1),(0,1,2). The final elements of these permutations are 0,1,0,2,1,2 which are the initial terms of this sequence. The same holds for any n >= 0.
MAPLE
a:= proc(n) local h, k, m;
h, k:= n, 0;
for m from 2 while h>0 do
k:= k+ `if`(irem(h, m, 'h')+k+1 < m, 0, 1)
od; k
end:
seq(a(n), n=0..130); # Alois P. Heinz, Jun 23 2012
MATHEMATICA
a[n_] := Module[{h, k, m, r}, h = n; k = 0; For[m = 2, h>0, m++, k = k + If[{h, r} = QuotientRemainder[h, m ]; r+k+1 < m, 0, 1]]; k]; Table[a[n], {n, 0, 130}] (* Jean-François Alcover, Jun 11 2015, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
David W. Wilson, Jun 23 2012
STATUS
approved