Question: "I don't know the number of things today. There are two things left in three, three in five, three in five, and two in seven. Ask ry ?"
According to today's statement: divide a number by 3 + 2, divide by 5 + 3, divide by 7 + 2, and find this number...
At present, I still don't understand Sun Tzu's theorem (China's surplus theorem). So I will give my own stupid method...
Solution: If this number is set to N, then: N % 3 = 2; n % 5 = 3; n % 7 = 2;
Order: N = T1 * 3 + 2; n = T2 * 5 + 3; n
= T3 * 7 + 2;
Then: 3 * T1 = 7 * T3; (1;
3 * T1 = 5 * t2 + 1; (2) type;
7 * T3 = 5 * t2 + 1; (3) type;
Obtained from (1): (3, 7) = 1; then T3 is a multiple of 3, and T1 is a multiple of 7.
The formula (2) and (3) can be 5*12 + 1 except 3, 7, T1, and T2;
Then, 5 * t2 + 1 can be divided into multiples of 21.
Then, 5 * t2 = 21 * k-1 (k is an integer). Now let's think about it in another way. We can divide the number of five by a single digit, which must be 0, or 5 (proving in number theory ),
If the problem is converted to 21 * K, the number of digits in the result must be 1 or 6. Obviously, K can be 1, 6, 11, 16, 31 .... the equation will be created...
Return to the initial n value, n = 5 * t2 + 3 = 21 * k + 2; (k = 1, 6, 11, 16, 21, 26 .... the number of equals columns )....
So N can be set to 23,128...
Code implementation:
# Include <iostream>
Using namespace STD;
Int main (){
For (INT I = 1; I <= 10000; I ++ ){
If (I % 3 = 2 & I % 5 = 3 & I % 7 = 2)
Cout <I <"";
}
Cout <Endl;
For (INT I = 1; 21 * I + 2 <= 10000; I + = 5 ){
Cout <21 * I + 2 <"";
}
While (1 );
}
Dear user !! Make a good comparison. All items are consistent ..