I saw this problem when I checked my interview experience,
First, Glossary:
The number of input records is the same as that of the last query, for example, 121,12321.
Prime Number: a product can only be divided by 1 and itself.
The number of input objects: that is, the number of input objects and the number of input objects.
Okay. Now that the concept is fully explained, let's write it.ProgramNow.
1 # Include <stdio. h> 2 # Include <stdlib. h> 3 # Include <math. h> 4 /* * 5 Determines whether M is a prime number. 6 @ Return 1: prime number, 0: not a prime number 7 * */ 8 Int SS ( Int M ){ 9 For ( Int I = 2 ; I <= SQRT (m); I ++ ) 10 If (! (M % I )) 11 Return 0 ; 12 Return 1 ; 13 } 14 15 /* * 16 Determine whether M is the number of replies 17 @ Return 1: return, 0: not return 18 * */ 19 Int Huiwen ( Int M ){ 20 Int X = 0 , Y; 21 Y = M; 22 While (Y ){ 23 X = x * 10 + Y %10 ; 24 Y/= 10 ; 25 } 26 If (M = X) 27 Return 1 ; 28 Else 29 Return 0 ; 30 } 31 32 Int Main () 33 { 34 /* * 35 The requirements for the number of whitelists: 36 1-digit must be odd 37 2. Number of replies + Prime Number 38 3. Only Exception: 11 39 * */ 40 // Print 11 Directly 41 Printf ( " The number of whitelists: % d \ r \ n " , 11 ); 42 Int J = 1 ; // Base 43 Int K = 3 ; // Boundary 44 Int L; 45 While (J < K ){ 46 L = POW (100 , J ); 47 For ( Int I = L + 1 ; I < 10 * L; I ++, I ++ ) 48 If (Huiwen (I )&& SS (I )) 49 Printf ( " The number of whitelists: % d \ r \ n " , I ); 50 J ++ ; 51 } 52 }
Why do we need odd numbers of replies? Because the number of even bits is destined to be divisible by 11, it is definitely not a prime number.
So here we only need to consider 101-999,10001-99999, and so on odd digits, so we can reduce a lot of loops.