A308832 Numbers that are palindromic in bases 3, 9 and 27.
0, 1, 2, 4, 8, 10, 20, 364, 728, 730, 1460, 2920, 5840, 7300, 7381, 7462, 14600, 14681, 14762, 265720, 531440, 531442, 532171, 532900, 1062884, 1063613, 1064342, 2125768, 2128684, 2131600, 4251536, 4254452, 4257368, 5314420, 5321710, 5329000, 5373550, 5380840, 5388130, 5432680, 5439970, 5447260
Offset: 1
Links
- A.H.M. Smeets, Table of n, a(n) for n = 1..2586
Programs
-
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 *)
-
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
-
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)
Comments