Find the five digits whose single digit is 6 and can be divided by three.
According to the principle that the total number of users that can be divided by three can also be divided by three, and the single position 6 can be divided by three, so we only need to consider the high level 4, the following method can be used to obtain the final result:
1 /*==================================
2 Copyright (C) 2014 All rights reserved.
3 FileName:3.c
4 author:donald
5 date:2014/08/16/ 23:35:55
6 ===================================*/
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 int main(int argc, const char *argv[])
12 {
13 int index,cnt ;
14 for(index = 1000;index < 9999;index ++){
15 if(index % 3 == 0){
16 cnt ++;
17 printf("%8d",index*10 + 6) ;
18 }
19 }
20 printf("\nresult is %d \n",cnt);
21 return 0;
22 }
In the five-digit number, there must be at least one six digits, and how many digits can be divisible by three?
12504
Solution 1)
First, divide the expected five-digit number into two types:
[1] If the number is six, and the number of five digits that can be divided by three matches the requirement
(9999-0000) limit 3 + 1 = 3334
[2] five digits whose number is not 6 and can be divided by three
(1) The single digit is 6:
[(9999-1002) limit 3 + 1]-[(999-000) limit 3 + 1] = 2666
The 10 digits are 6, the hundred digits are 6, and the thousands of digits are 6: both are 2666
(2) 6 digits and 10 digits:
[(999-102) limit 3 + 1]-[(99-00) limit 3 + 1] = 266
6 digits, 6 digits, 6 digits, 6 digits, 6 digits, 6 digits, 6 digits, 6 digits, 6 digits, 266 digits, 6 digits
(3) 6 digits, 10 digits, and hundreds of digits:
[(99-12) limit 3 + 1]-[(9-0) limit 3 + 1] = 26
Digits, 10, and thousands are 6, digits, hundreds, and thousands are 6, and digits of 10, hundreds, and thousands are 6: 26
(4) 6 digits:
36666, 96666, 2 in total
2666 × 4-266 × 6 + 26 × 4-2 = 9170
Therefore, the expected five-digit number is 3334 + 9170 = 12504.
Solution 2)
Total multiples of 3 in all five digits (99999-9999)/3 = 30000
1, 4, 7 is 3 k + 1, expressed as 1
2, 5, 8 is 3 k + 2, expressed as 2
0, 3, 9 is 3 k, expressed as 0
There are 7 types of data that do not contain 6 and are multiples of 3.
(1) 00000, a total of 3 ^ 5-3 ^ 4 = 162
(2) 11100, total [5! /(3! * 2!)] * 3 ^ 5-(4! /3 !) * 3 ^ 4 = 2106
(3) 12000, total (5! /3 !) * 3 ^ 5-(4! /2 !) * 3 ^ 4 = 3888
(4) 11112, total (5! /4 !) * 3 ^ 5 = 1215
(5) 11220, total [5! /(2! * 2!)] * 3 ^ 5-[4! /(2! * 2!)] * 3 ^ 4 = 6804
(6) 22200, total [5! /(3! * 2!)] * 3 ^ 5-(4! /3 !) * 3 ^ 4 = 2106
(7) 12222, total (5! /4 !) * 3 ^ 5 = 1215
(1 )~ (7) A total of 17496
30000-17496 = 12504
C language source code: the total number of five digits that can be divided by three and have a limited number of five digits.
In fact, there is no need to calculate the value of k, because as long as the number of outputs is enough, then the end is 6. Then you only need to determine the number of the four digits from 1000 to 9999 that can be divisible by three. 6. If three digits can be divisible, the first four digits are calculated. If three digits can be divisible, the conditions are met.
Main ()
{
Int I, j, k, m, count;
M = 0;
For (I = 1000; I <= 9999; I ++)
{K = 10 * I + 6; // It is useless.
For (j = I; j <= 0; j ++) {// Add four digits
M + = j % 10;
}
If (m + 6) % 3 = 0 count ++;
}
Printf ("% d", count );
}