How to (efficiently) compute the sum of the digits of evey number lying between two given numbers? Given two integers A and B , how to efficiently compute the sum of all the digits of every number int the set  $\{N | A \le N \le B \} $.
For example: A = 100  and B = 777, then the required answer is 8655.
I am interested in deriving an formula/efficient algorithm for the same.

Just summing them altogether first would produce a number that has the same digit-sum as stringing them altogether.
For example: 101-103
101, 102, 103 -> 1+0+1+1+0+2+1+0+3 -> 9
101+102+103 = 306 = 3+0+6 = 9
Use the Gauss method to add the numbers quickly...
That is, if I have the numbers in a set like 1-10
1+2+3+4+5+6+7+8+9+10 = 1+10+2+9+3+8+4+7+5+6 = (1+10)+(2+9)+(3+8)+(4+7)+(5+6) = (11)+(11)+(11)+(11)+(11) = 11*(10/2) <--- 10 is the upper-limit of the given range.
Then add the digits together by dividing by 10 and adding the remainder to one storing variable. (ex. 52 = 5+2 = 7.... 52 --> 52/10 --> 5r2... "2"+? .... 5/10 = 0r5 --> "2"+"5" = 7.)
