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. 
 A: 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.
A: I'll take the first question, which is the simplest of the 3.  It will make things easier if we start looking at the sum of the digits of all numbers between 0 and 999,999.  Start by adding leading 0s to pad all numbers to 6 digits.  
Consider the first digit.  If the first digit is a 1, there are 10 choices for each of the remaining 5 digits.  So there are $10^5$ numbers in that range that have 1 as a first digit.  The same can also be said of any other number as the first digit.  So if you sum the first digit of all those numbers together, you get $(1+2+3+4+5+6+7+8+9)\times10^5=4,500,000$.  The same is true for the remaining digits.  So the sum of all the digits of all numbers between 0 and 999,999 is $4,500,000\times 6=27,000,000$.
We counted 0, which we didn't really want, but the sum of the digits of 0 is 0, so that doesn't affect our sum.  That leaves just 1,000,000 which has a digit sum of 1, making our final total 27,000,001.
A: 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
A: Let our sum be S: add them forwards and backwards:
1 + 2  +  3  + ... +n = S  and 
n+(n-1)+(n-2)+ ... +1 = S
add the rows and you get the sum of n terms each equal to (n+1).
This is then equal to n(n+1) = 2 S
Therefore
S = n(n+1)/2
You can easily compute the result for any n.
For n = 5 we have 1+2+3+4+5 = (5*6)/2 = 15
For n = 1000000 the result is:
10^6(10^6+1)/2 = (5 x 10^5)(10^6+1) = 5x10^11 + 5x10^5 = 
500,000,500,000
Thanks to first grader Carl Friedrich Gauss!!   
