A378564 a(n) is the number of n-digit nonnegative integers with the median of the digits equal to one of the digits.
10, 9, 900, 1665, 90000, 232710, 9000000, 29055165, 900000000, 3413319138, 90000000000, 386095933170, 9000000000000, 42568084276236, 900000000000000, 4607838122919165, 90000000000000000, 491998811785538730, 9000000000000000000, 51983526276872387430, 900000000000000000000, 5447302810160797285236
Offset: 1
Examples
From _David A. Corneth_, Dec 03 2024: (Start) a(3) = 900 as every positive integer between (inclusive) 100 and 999 contains its median. The median is the middle digit after sorting which is in the digits. a(4) = 1665. For example 2558 has digits sorted and the median, 5 is in the digits of 2558 and any permutation of digits of 2558. There are 12 such permutations so 2558 contributes 12 towards the total of a(4). 0258 has digits sorted (but a leading 0) and has 24 permutations. To account for the leading 0 we remove it and deduce the number of permutations from what is left, namely 258. That has 6 permutations. So in total 0258 adds 24 - 6 = 18 towards the total of a(4). (End)
Links
- Chai Wah Wu, Table of n, a(n) for n = 1..47 (terms 1..27 from David A. Corneth)
- David A. Corneth, PARI program
Programs
-
Mathematica
a[n_]:=If[OddQ[n], KroneckerDelta[n,1]+9*10^(n-1), Module[{c=0}, For[k=10^(n-1), k<=10^n-1, k++, If[MemberQ[digits=IntegerDigits[k], Median[digits]], c++]]; c]]; Array[a, 7]
-
PARI
\\ See Corneth link
-
Python
from math import prod, factorial from itertools import combinations_with_replacement from collections import Counter def A378564(n): if n==1: return 10 if n&1: return 9*10**(n-1) c, f = 0, factorial(n-1) for p in combinations_with_replacement(range(10),n): if max(p): a = sorted(p) b = a[len(a)-1>>1]+a[len(a)>>1] if b&1^1 and b>>1 in p: v = Counter(d for d in p if d).values() s = sum(v) q = prod((factorial(i) for i in v))*factorial(n-s) c += sum(f*i//q for i in v) return c # Chai Wah Wu, Dec 14 2024
Formula
a(2*n-1) = 9*10^(n-1) with a(1) = 10.
a(n) = A063945(n) for n odd.
Extensions
More terms from David A. Corneth, Dec 03 2024