OFFSET
1,2
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..400
FORMULA
a(n) = 2 <=> n in { A000040 }.
EXAMPLE
a(4) = 7: 1234, 1324, 1423, 2314, 2413, 3412, 4321.
MAPLE
b:= proc(u, o, t, d) option remember; `if`(u+o=0, 1,
`if`(t=d, add(b(u-j, o+j-1, 1, d), j=1..u),
add(b(u+j-1, o-j, t+1, d), j=1..o)))
end:
a:= proc(n) option remember; `if`(n=1, 1, 2+add(
b(n, 0, d$2), d=numtheory[divisors](n) minus {1, n}))
end:
seq(a(n), n=1..35);
MATHEMATICA
b[u_, o_, t_, d_] := b[u, o, t, d] = If[u + o == 0, 1,
If[t == d, Sum[b[u - j, o + j - 1, 1, d], {j, 1, u}],
Sum[b[u + j - 1, o - j, t + 1, d], {j, 1, o}]]];
a[n_] := a[n] = If[n == 1, 1, 2 + Sum[b[n, 0, d, d], {d, Divisors[n] ~Complement~ {1, n}}]];
Array[a, 35] (* Jean-François Alcover, Aug 01 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Jul 25 2018
STATUS
approved