A308918 a(n) is the number of palindromic numbers with 7 digits in base n which are also palindromic in base n+1.
0, 0, 1, 2, 7, 8, 13, 18, 27, 35, 50, 61, 75, 79, 96, 113, 120, 150, 173, 180, 204, 227, 245, 274, 295, 318, 346, 363, 398, 438, 448, 484, 524, 537, 584, 625, 648, 707, 749, 771, 830, 882, 914, 983, 1041, 1073, 1143, 1207, 1238, 1307, 1372, 1405, 1480, 1544, 1573, 1645
Offset: 2
Crossrefs
Cf. A048268.
Programs
-
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; a(n) = {my(d=7, p = n^(d-1)-1, nb = 0); while (p < n^d, p = nextpal(p, n+1); if (ispal(p, n), nb++);); nb;} \\ 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 ispal(n,b): if n%b == 0: return 0 else: nn, m = n, 0 while n > 0: n, m = n//b, m*b+n%b return m == nn n, d = 1, 7 while n < 20000: n = n+1 p = n**(d-1)-1 a = 0 while p < n**d: p = nextpal(p,n+1) if ispal(p,n): a = a+1 print(n,a)
Comments