Some digit summation problems What is the sum of the digits of all numbers from 1 to 1000000? 
  In general, what is the sum of all digits between 1 and N?
  f(n) is a function counting all the ones that show up in 1, 2, 3, ..., n. so f(1)=1, f(10)=2, f(11)=4 etc. When is the first time
  f(n)=n.
  


So for the first question, I tried thinking about it such that between 000000 and 999999, each digit will appear the same number of times, so if I find out how many times one digit appears I can just apply that to the other 9 digits (then add 1 for the last number 1000000): 

(the number of times 1 digit appears)*(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) = ...

1 Appears once between 1 and 9
1 appears 11 times between 1 and 99
1 appears 11 * 10 + 10 = 120 times between 1 and 999
...I'm not sure how to find the pattern

But firstly I'm not so sure of my approach, secondly I'm not sure about how to find how many times one particular number appears, and third if this method worked it doesn't seem very good for solving the second part of the question. 

Lastly, I had a similar question to the first 2 (question 3) so I just grouped it with those. I hope they are related, and if not I can make a seperate question for that one.

Thanks.
For question three, we can simply compute.  Besides n=1, the next solution is 199981, as generated by this PARI/GP code:

Define $r(n)$ to be the number of ones in the digits of $n$:


r(n) = nn=n;cc=0;while(nn>0,if((nn%10)==1,cc=cc+1);nn=floor(nn/10));return(cc)


Then run a loop and output $i$ if the sum of $r(i)$ from 1 up to $i$ is equal to $i$:

yy=0;for(i=1,199981,yy=yy+r(i);if(yy==i,print(i)))


The output is this:


1
199981


This shows $f(1)=1$ and $f(199981)=199981$ and there are no other solutions less than 199981.

Similarly for question one, we define $g(n)$ to be the sum of the digits of $n$:


g(n) = nn=n; cc=0; while(nn>0,cc=cc+(nn % 10);nn=floor(nn/10));return(cc)


then calculate:


sum(i=1,1000000,g(i))


which yields the sum 27000001.
Formula for this question is,
X=n(n+1)/2
X=1000000(1000000+1)/2
X=1000000(1000001)/2
X=1000000(500000.5)
X=500,000,500,000