OFFSET
0,3
COMMENTS
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..10000
FORMULA
a(n) <= n + 1 with equality iff n = 10^k for some k > 0.
EXAMPLE
PROG
(PARI) { base = 10; k = 0; r = 0; for (n=0, 67, while (r<n, r = fromdigits(Vecrev(digits(k++, base)), base); ); print1 (k ", ")) }
(Python)
def A340835(n):
if n == 0:
return 0
s = str(n)
for i, x in enumerate(s):
if x != '9':
break
else:
return n
s1, s2 = s[:i+1], s[i+1:]
if s2 == '':
if s1[-1] == '0':
return int(str(n+1)[::-1])
else:
return int(s[::-1])
if int(s2) <= 1:
return int('1'+s2[-2::-1]+s1[::-1])
else:
return int('1'+'0'*(len(s2)-1)+str(int(s1)+1)[::-1]) # Chai Wah Wu, Mar 14 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Mar 13 2021
STATUS
approved