login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

2^n-th palindromic number.
3

%I #9 Jun 14 2024 01:49:06

%S 1,2,4,8,77,232,555,2992,15751,41314,92529,1049401,3097903,7193917,

%T 63855836,227696722,555373555,3107337013,16214541261,42428982424,

%U 94857775849,1097153517901,3194305034913,7388609068837,67772177127776

%N 2^n-th palindromic number.

%H Chai Wah Wu, <a href="/A099280/b099280.txt">Table of n, a(n) for n = 0..1661</a>

%t NextPalindrome[n_] := Block[ {l = Floor[ Log[10, n] + 1], idn = IntegerDigits[n]}, If[ Union[ idn] == {9}, Return[n + 2], If[l < 2, Return[n + 1], If[ FromDigits[ Reverse[ Take[ idn, Ceiling[l/2]]]] FromDigits[ Take[ idn, -Ceiling[l/2]]], FromDigits[ Join[ Take[ idn, Ceiling[l/2]], Reverse[ Take[ idn, Floor[l/2]]] ]], idfhn = FromDigits[ Take[ idn, Ceiling[l/2]]] + 1; idp = FromDigits[ Join[ IntegerDigits[ idfhn], Drop[ Reverse[ IntegerDigits[ idfhn]], Mod[l, 2]]]] ]]]]; k = 1; np = 0; Do[ While[np = NextPalindrome[np]; k != 2^n, k++ ]; Print[np], {n, 26}]

%o (Python)

%o def A099280(n):

%o if n == 0: return 1

%o m = 1<<n-1

%o k = (m<<1)+1

%o y = 10*(x:=10**(len(str(m))-1))

%o return (c:=k-x)*x+int(str(c)[-2::-1]or 0) if k<x+y else (c:=k-y)*y+int(str(c)[-1::-1]or 0) # _Chai Wah Wu_, Jun 13 2024

%Y Cf. A083816.

%K base,nonn

%O 0,2

%A _Robert G. Wilson v_, Oct 04 2004