Finding 12 as sum of digits between the numbers 1 and 1,000,000 is like finding coefficient of x^12 between 1 and 999,999 (as the digits of course of 1,000,000 don't sum up to 12).
Now all the numbers a1+a2+a3+a4+a5+a6 (number of digits in 999,999) should be between 0 and 9.
So, this is equivalent to finding coefficient of x12 in (x0 + x1 + x2 +...... +x9)6
this simplifies to x12 in [(1-x10)/(1-x)]6 sum of GP series
= coefficient of x12 in (1-x10)6 . (1-x)-6
=coefficient of x12 in [(1-x)-6 - 6C1 x10 (1-x)-6 + ...............] Binomial expansion
=12+6-1C6-1 - 6. [coefficient of x2 in (1-x)-6]
=17C5 - 6. 7C5
=6188 - 126
=6062
f(k)