login
Number of binary necklaces of n beads for which a cut exists producing a palindrome.
3

%I #41 May 08 2021 06:29:48

%S 2,2,4,3,8,6,16,9,32,20,64,34,128,72,256,129,512,272,1024,516,2048,

%T 1056,4096,2050,8192,4160,16384,8200,32768,16512,65536,32769,131072,

%U 65792,262144,131088,524288,262656,1048576,524292,2097152

%N Number of binary necklaces of n beads for which a cut exists producing a palindrome.

%C For odd n, this corresponds to A029744, necklaces of n beads that are the same when turned over. For even n, consider the necklace "01", which satisfies A029744 but cannot be cut to produce a palindrome.

%H Hugo Pfoertner and Robert G. Wilson v, <a href="/A185333/b185333.txt">Table of n, a(n) for n = 1..1000</a>

%t f[n_] := If[OddQ@ n, 2^(n/2 + 1/2), Block[{k = IntegerExponent[n, 2] - 1}, 2^(n/2 - 1) + 2^((n/2 - 2^k)/(2^(k + 1)))]]; Array[f, 41] (* _Robert G. Wilson v_, Aug 08 2011 *)

%o (Python)

%o def a(n):

%o if n%2: return 2**((n + 1)//2)

%o k=bin(n - 1)[2:].count('1') - bin(n)[2:].count('1')

%o return 2**(n//2 - 1) + 2**((n//2 - 2**k)//(2**(k + 1)))

%o print([a(n) for n in range(1, 101)]) # _Indranil Ghosh_, Jun 29 2017

%Y Cf. A185376, A025480. - _Hugo Pfoertner_, Jul 30 2011

%K nonn

%O 1,1

%A _Tony Bartoletti_, Feb 20 2011