How many integers between 1 and 10^21 are such that the sum of their digits is 2?

Capture

Can any one explain the process to solve it?

Combinatorics. Notice that if the sum is 2, the number must either be of the form

  • “00000002” - of which there are 21 ways since we are looking for all numbers up to 1021
  • “11000000000” - of which there are \frac{21!}{2! 19!} → 210 ways.

Sum them up: 210 + 21 = 231.