A375968 a(n) is the least number with the same digit average as n.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 12, 2, 14, 3, 16, 4, 18, 5, 1, 12, 2, 14, 3, 16, 4, 18, 5, 29, 12, 2, 14, 3, 16, 4, 18, 5, 29, 6, 2, 14, 3, 16, 4, 18, 5, 29, 6, 49, 14, 3, 16, 4, 18, 5, 29, 6, 49, 7, 3, 16, 4, 18, 5, 29, 6, 49, 7, 69, 16, 4, 18, 5, 29, 6
Offset: 0
Examples
The first terms, alongside the corresponding digit average, are: n a(n) Digit average -- ---- ------------- 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 1/2 11 1 1 12 12 3/2 13 2 2 14 14 5/2 15 3 3
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..10000
Programs
-
Mathematica
a[n_]:=Module[{k=0}, While[Mean[IntegerDigits[k]]!=Mean[IntegerDigits[n]], k++]; k]; Array[a,76,0] (* Stefano Spezia, Sep 07 2024 *)
-
PARI
a(n, base = 10) = { my (d = digits(n, base), avg = vecsum(d) / max(1, #d)); if (avg==0, 0, my (t = vector(denominator(avg)), r = numerator(avg), x); t[1] = 1; r--; forstep (k = #t, 1, -1, t[k] += x = min(r, base-1); r -= x;); fromdigits(t, base);); }
Comments