A378203 Number of palindromic n-ary words of length n that include the last letter of their respective alphabet.
1, 1, 1, 5, 7, 61, 91, 1105, 1695, 26281, 40951, 771561, 1214423, 26916709, 42664987, 1087101569, 1732076671, 49868399761, 79771413871, 2560599031177, 4108933742199, 145477500542221, 234040800869107, 9059621800971105, 14605723004036255, 613627780919407801
Offset: 0
Examples
a(0) = 1: (). a(1) = 1: (a). a(2) = 1: (b,b). a(3) = 5: (a,c,a), (b,c,b), (c,a,c), (c,b,c), (c,c,c).
Programs
-
Maple
a:= n-> (h-> n^h-`if`(n=0, 0, (n-1)^h))(ceil(n/2)): seq(a(n), n=0..25); # Alois P. Heinz, Nov 21 2024
-
Mathematica
h[n_] := Ceiling[n/2];a[n_] := n^h[n] - (n - 1)^h[n];Join[{1},Table[a[n],{n,25}]] (* James C. McMahon, Nov 21 2024 *)
-
PARI
h(n) = {ceil(n/2)} a(n) = {n^h(n)-(n-1)^h(n)}
-
Python
def A378203(n): return n**(m:=n+1>>1)-(n-1)**m if n else 1 # Chai Wah Wu, Nov 21 2024
Formula
a(n) = n^h(n) - (n-1)^h(n) for n > 0, where h(n) = ceiling(n/2).
a(n) = A047969(n-1,h(n)-1) for n > 0.