OFFSET
2,1
COMMENTS
LINKS
Christian Perfect, Table of n, a(n) for n = 2..1000
EXAMPLE
a(8) = 3 because the first 6 powers of 3 are palindromes in base 8, which is more than any other number in the range 2..8 (here, m = 6).
PROG
(Python)
def to_base(n, b):
...s = []
...while n:
......m = n%b
......s = [m]+s
......n = (n-m)//b
...return s
.
def is_palindrome(n):
...return n==n[::-1]
.
def num_palindromes(n, b):
...if n<2:
......return 0
...t = 1
...while is_palindrome(to_base(n**t, b)):
......t+=1
...return t-1
.
def most_palindromes(b):
...return max(range(2, b+1), key=lambda n:num_palindromes(n, b))
(PARI) a(n)=v=[-1]; for(k=2, n, i=1; c=0; while(i, d=digits(k^i, n); if(Vecrev(d)==d, c++); if(Vecrev(d)!=d, break); i++); if(c>v[#v], v=concat(v, c); m=k)); m
vector(100, n, a(n+1)) \\ Derek Orr, Jun 18 2015
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Christian Perfect, Jun 09 2015
STATUS
approved