Combinatorial math addition and multiplication laws

o Example 1.1.6

•1) Find the number of positive integers containing 1 less than 10000

•2) Find the number of positive integers containing 0 less than 10000

 

1) Positive integers less than 10000 without 1 can be regarded as 4 digits, except 0000. Therefore, there are 9×9×9×9-1=6560.

    Including 1: 9999-6560=3439

In addition: there are 10^4 all 4-digit numbers, 9^4 four-digit numbers without 1, and the difference of two 4-digit numbers with 1: 10^4 -9^4 = 3439.

 

2) There are 9 1-digit numbers without 0, 9^2 2-digit numbers, 9^3 3-digit numbers, and 9^4 4-digit numbers, so positive integers less than 10000 without 0 are

     9+9^2 +9^3 +9^4 =(95-1)/(9-1)=7380;

           Positive integers including 0 and less than 10000 are: 9999-7380=2619

Note: "Include 0" and "Include 1" cannot be directly applied. 0019 contains 1 but not 0. There are many similar implicit provisions in the combined exercises, and special attention should be paid to them.

let c1 = 0
let c0 = 0

for (let i = 1; i < 10000; i++) {
  String(i).includes('0') ? c0++ : c0
  String(i).includes('1') ? c1++ : c1
}
console.log(c0, c1)
2619 3439

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325081283&siteId=291194637