Find sum of digits of number from 1 to 10^6
I hope you undestand. The basic idea is to count how many times a digit occurs in a number.