aloneontheedge wrote:
Hey,
i did not understand how did u arrive at the pattern,would u plz explain?
Pattern I found is:
Summation of { [The sum you want to find for - The range header]+1 } upto 1
This will give the number of numbers that have the sum you want in
that particular range.
In the current example:
The sum you want to find for =5
The range header = 0,1,2,3,4,5 [because Ranges start with 0001,1000,2000,3000,4000,5000]
Therefore result when range header is 0 can be calculated as
We get (5-0)+1 = 6
Hence summaton of 6 to 1 is 6+5+4+3+2+1 = 21
Similarly when the range header is 1, we will get 5+4+3+2+1 = 15
Summation of all the range headers gives us the total count of numbers with sum of digits as 5.
i.e; 21+15+10+6+3+1 = 56
Hope this helps.. Let me know if you dont get it.
Also, Let us take some other example to see if its correct.
Let us say we need to find the count of numbers less than 10000 with sum of digits as 1.
We know that the numbers are 1,10,100,1000 -> only 4.
Let us see if my pattern works here.
The sum you want to find for =1
For First range header -> 0.
count = (1-0)+1 = 2, Hence summation upto 1 = 2+1 = 3
For second range header ->1
count = (1-1)+1 = 1, Hence summation = 1
Hence total number of numbers with sum of digits as 1 = 3+1 = 4.
Hope this helps!!