[quote="JeroenReunis"]Hello all. This is my first question. Hopefully someone could clarify.
Q: How many integers between 1 and 10^21 are such that the sum of their digits is 2?
My answer: : Every level has 2 digits when there are two 1's in the number.
Level 1 : 11 = 1
Level 2 : 101 & 110 = 2
Level 3 : 1001 , 1010 & 1100 = 3
Level 4 : 10001, 10010, 10100 & 11000 = 4
So apparently every level you rise, 1 more integer with sum of digits 2 is added.
In this case,starting from the first "0" this number -> 1.000.000.000.000.000.000.000 (=10^21) has 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21 =231 which is exactly the correct answer.
However, the OFFICIAL answer mentions this solution:
10^21 is a 22 digit number, this means that all integers betweeen 1 and 10^21 will have at most 21 digits. Now for the purpose of this question we will say that all the numbers in this range have exactly 21 digits. We do this by including several leading 0's of a number. So e.g. we can write 10 million 1 hundred thousand as 000.000.000.000.010.100.000 Similarly we could write 20.000 as a 21 digit number. Now for a number to have the sum of its digits to equal 2 we need to consider 2 possible cases. Case 1 is that we have 2 1's in our number and then 19 0's. Case two is that we have one 2 and 19 zero's. To find out the number of 21 digits number with 19 zero's and two 1's. This we can do in 21C2 ways. If we plug this in the nCr formula we get 210. In Case two we have 21C1 = 21 ways. So 210 + 21 = 231.
Is my approach wrong?? I think the "official" answer is quite strange since 000.020.000.000.000.000.000 is not really an integer?
Any help is welcome, thanks in advance!![/quote
hi Jeroen ...your approach is ok but u r going wrong on two accounts although u r getting the correct ans
1) as far as your counting is considered for two 1's...
the last part where u have considered 21 at level 21 is wrong.. in ur way there should be only 20 levels..
the reason is 10^21 is the lowest 21 level digit number..that is 10000....000. and one lower than it is 999..20 times so it cannot have 1000..20 times...01
2) so the ans is 1+2+...+20, which is 210.. now what about rest 21.. this is the second mistake.. what about digit 2 with all rest digits as 0 for eg 2,20,200..
2*10^0,2*10^1,2*10^2,.. till 2*10^20=21 such numbers
combine the two 210+21=231 s
_________________