The method I used for this problem involved first coming up with a formula that says how many times a digit has been used in all n models.

n = k*10^i + m for some k,m with 0 <k <10, m < 10^i f(d,n) = (number of d's used getting to k*10^i from digits 0 to (i-1)) +

(number of d's used by #'s 10^i to n from digit i) + f(d,m)

f(d,n) = i*k*10^(i-1) + (if (d < k) 10^i else if (d == k) m+1 else 0) + f(d,m)

This doesn't count 0's, which should be ok as they are not used as often as other digits. From the formula, it is clear that f(1,n) is never less than f(d,n) for 1<d<10. So I just calculated f(1,n) for various n (with some help from bc).

I quickly discovered that for n = 2*10^15, f(1,n) = 2*n. After further trials I determined that for n = 1999919999999981, f(1,n) = 2*n + 1. This appears to be the smallest n with f(1,n) > 2*n.

lib/config.php:156: Notice: Undefined variable: accept

lib/DbaDatabase.php:134: Warning: dba_replace() [<a href='function.dba-replace'>function.dba-replace</a>]: You cannot perform a modification to a database without proper access