1

The following formula to calculate the appearance of the character 1 (one digit) of the numbers 1 to 1000:

P(1) + p(2) + P(3) + 1
(9.10^0 - 8.9^0) + (9.10^1 - 8.9^1) + (9.10^2 - 8.9^2) + 1
(9.1 - 8.1) + (9.10 - 8.9) + (9.100 - 8.81) + 1
(9-8) + (90-72) + (900-648) + 1
1 + 18 + 252 + 1
272

so the appearance of the character 1 on numbers 1 to 1000 as many as 272 times. I tried to calculate if the character that consists of 2 digits, for example 14, I tried to change the formula above to:

P(1) + p(2) + P(3) + 1
(90.100^0 - 80.90^0) + (90.100^1 - 80.90^1) + (90.100^2 - 80.90^2) + 1
(90.1 - 80.1) + (90.100 - 80.90) + (90.10000 - 80.8100) + 1
(90-80) + (9000-7200) + (900000-648000) + 1
1 + 18 + 252 + 1
272

I think the result is not appropriate, because the appearance of the character 14 from 1 up to 10000 instead of 272, but 299 times. Is there something wrong with the formula above, or may have a better solution?

aon
  • 89

1 Answers1

0

Here's one way to calculate the number of appearances of the digit $1$ in all the numbers from $1$ to $1000$:

It appears once in $1000$. How many times does it appear in the numbers from $1$ to $999$?

It appears once in every number having exactly one $1$, and that is $3\times 9^2$ (because the number is of the form $\boxed{\_\ \_\ \_}$, and the $1$ could be in any one of the three places, with the other two places being any digit from $0$ to $9$ except $1$).

It appears twice in every number having exactly two $1$s, and that is twice of $3 \times 9$, so $2 \times 3 \times 9$.

It appears three times in the number $111$, so that's $3 \times 1$.

Adding these up, we get $1 + 3 \times 9^2 + 2 \times 3 \times 9 + 3 \times 1 = 1 + 243 + 54 + 3 = 301$.

Now, you might get $272$ if you forget to multiply by $2$ for the numbers in which $1$ appears twice and by $3$ for $111$ (because then you get $1 + 3 \times 9^2 + 3 \times 9 + 1 = 1 + 243 + 27 + 1 = 272$). But you seem to have done it in a different way, so I'm not sure how you got the same incorrect answer.

However, another much easier way to calculate this is as follows: In how many numbers does $1$ appear in the unit's place of all the integers from $1$ to $999$? In $100$ numbers (because if the number is of the form $\boxed{\_\ \_\ 1}$, the first two digits could be any of the ten digits $0-9$). Similarly, there are $100$ numbers in which $1$ appears in the ten's place, and $100$ in which it appears in the hundred's place. So totally there are $100 + 100 + 100 = 300$ appearances. Adding the one appearance in $1000$, we get $301$.


Using the second method, we can count the number of appearances of the number $14$ in the integers from $1$ to $10000$:

The number $14$ can appear in the following three places: $\boxed{1\ 4\ \_\ \_}$, $\boxed{\_\ 1\ 4\ \_}$, $\boxed{\_\ \_\ 1\ 4}$

The other two digits can be any of the ten digits from $0 - 9$. Thus the total number of appearances is $3 \times 10^2 = 300$.

In general, for integers from $1$ to $10^n$, the number $14$ can appear in the places:
$\boxed{1\ 4\ \_\ \_\ \ldots\ \_},\ \boxed{\_\ 1\ 4\ \_\ \ldots\ \_}, \ldots, \boxed{\_\ \_\ \ldots\ \_\ 1\ 4}$

That makes $n - 1$ possible places, and for each such number, the remaining $n - 2$ digits can be any of ten digits, so there are $10^{n-2}$ numbers of each form. Thus, there are $(n - 1)10^{n-2}$ appearances of $14$ in all the integers from $1$ to $10^n$.
For example, $(3 - 1)10^{3 - 2} = 20$ appearances of $14$ in the integers from $1$ to $1000$.

Demonstration:
Here are all the numbers from $1$ to $1000$ that contain at least one $14$:

$014, 114, 214, 314, 414, 514, 614, 714, 814, 914$
$140, 141, 142, 143, 144, 145, 146, 147, 148, 149$

If you count the number of appearances of $14$, you will see there are $20$ of them. How? There are ten appearances in this exact form: $\boxed{\_ 1 4}$ (these are in the first row). Why ten? Because the first digit (indicated by the $\_$) can be any of the ten digits $0 - 9$. Similarly, there are ten appearances in the form $\boxed{14\_}$. That makes a total of $20$.

Similarly, if we consider four-digit numbers, we count appearances of the form $\boxed{1\ 4\ \_\ \_}$, appearances of the form $\boxed{\_\ 1\ 4\ \_}$, and those of the form $\boxed{\_\ \_\ 1\ 4}$. Each are $10 \times 10 = 100$ in number (because there are two positions to be filled, each by any of ten digits). This makes a total of $300$.

M. Vinay
  • 9,004
  • 1
    The second method is much simpler. I happened to solve a similar problem in my class using the first approach, and my student pointed out that it could be worked out using the second one. Still can't believe I didn't see it sooner. – M. Vinay Sep 06 '14 at 05:13
  • what if the display up to 10,000, or 1,000,000, or 10,000,000 to n-digit? – aon Sep 06 '14 at 06:53
  • Then it will be $4 \times 10^3 + 1 = 4001$ or $6 \times 10^5 + 1 = 600001$ or $7 \times 10^6 + 1 = 7000001$. If it is up to $10^n$, then it will be $n \times 10^{n - 1} + 1$. – M. Vinay Sep 06 '14 at 08:00
  • just that? nothing has changed in this section:"...+2×3×9+3×1" – aon Sep 06 '14 at 08:23
  • I tried it, counting occurrences of characters 14 (2 digits) from 1 to 4000, following formula as you do:

    1 + 4 x 9^3 + 2 x 3 x 9 + 3 x 1 1 + 2916 + 54 + 3 2974

    I compared with a program that I created using php, the results of the program stating the appearance of characters 14 from 1 to 40000 times as many as in 2176. and from 1 to 10000 as many as 299 times instead of 301 times.

    you try to see here, http://hjaya.wordpress.com/2010/11/09/menghitung-emergence-character-1-in-numbers-n-digit/

    – aon Sep 06 '14 at 09:17
  • sorry I still do not understand your point. Can you describe the calculation of the formula that you created to complete the counting occurrences of characters 14 from 1 to 10,000 and 1 to 10,000,000. so I can understand the difference. – aon Sep 08 '14 at 02:54
  • 20 times for 1-1000, that in accordance with a program that I created. you try to write the formula for the above quantifies 1000, for example, to 10,000, 10,000,000, etc.

    sorry if I bother you. thank you very much for your answer :)

    – aon Sep 08 '14 at 03:21
  • what the result is always worth an even number? you are great :) – aon Sep 08 '14 at 10:42
  • the person requesting the program said if it was not quite right, because the appearance of number 14 from 1 to 10,000 is 299 times. what do you think? – aon Sep 09 '14 at 01:17
  • @aon Look: http://codebin.org/view/6b4922a3 The number of integers that contain at least one '14' is 299. However, the actual number of appearances of '14' is 300, because one of those 299 numbers contains 14 twice (namely the number '1414'). – M. Vinay Sep 09 '14 at 01:27
  • if only want to count the number of integers only. how? where the formula has to be changed? – aon Sep 09 '14 at 01:32
  • I've made ​​a different question, you try to see http://math.stackexchange.com/questions/924399/how-many-integers-between-1-and-10n-contain-14. Can you answer it? :) – aon Sep 09 '14 at 02:17