OFFSET
1,3
COMMENTS
This sequence is infinite because it contains terms of the forms 729^k-1 (k>=0) and 729^k+1 (k>=0).
Let L_27 be the number of digits for a(n) represented in base 27.
If L_27 is odd, the digits are either in the set {0, 1, 2} or in {0, 4, 8} or in {0, 10_10, 20_10}.
If L_27 is even, the digits are either in the set {0, 13_10} or in {0, 26_10} or in {13_10, 26_10}.
Let L_3 be the length of a(n) if represented in base 3, then L_3 in {0,1,2,3} (mod 6).
LINKS
A.H.M. Smeets, Table of n, a(n) for n = 1..2586
MATHEMATICA
palQ[n_, b_] := PalindromeQ[IntegerDigits[n, b]]; aQ[n_] := AllTrue[{3, 9, 27}, palQ[n, #] &]; Select[Range[0, 6*10^6], aQ] (* Amiram Eldar, Jul 04 2019 *)
PROG
(Python)
def nextpal(n, base): # m is the first palindrome successor of n in base base
m, pl = n+1, 0
while m > 0:
m, pl = m//base, pl+1
if n+1 == base**pl:
pl = pl+1
n = n//(base**(pl//2))+1
m, n = n, n//(base**(pl%2))
while n > 0:
m, n = m*base+n%base, n//base
return m
def rev(n, b):
m = 0
while n > 0:
n, m = n//b, m*b+n%b
return m
n, a = 1, 0
while n <= 20000:
if a == rev(a, 9) and a == rev(a, 3):
print(n, a)
n = n+1
a = nextpal(a, 27)
(PARI) nextpal(n, b) = {my(m=n+1, p = 0); while (m > 0, m = m\b; p++; ); if (n+1 == b^p, p++); n = n\(b^(p\2))+1; m = n; n = n\(b^(p%2)); while (n > 0, m = m*b + n%b; n = n\b; ); m; } \\ after Python
ispal(n, b) = my(d=digits(n, b)); Vecrev(d) == d;
lista(nn) = {my(k=0); while (k <= nn, if (ispal(k, 3) && ispal(k, 9), print1(k, ", "); ); k = nextpal(k, 27); ); } \\ Michel Marcus, Jul 04 2019
CROSSREFS
KEYWORD
nonn,base
AUTHOR
A.H.M. Smeets, Jun 27 2019
STATUS
approved