Problem Description
Xiaoou33 is particularly interested in both prime numbers and the number of input objects. For example, 151 is both a prime number and a background. Xiaoou333 wants you to help him find the prime number in a certain range. Please write a program to find the number of prime numbers that meet the conditions between a and B. (5 <= a <B <= 100,000,000 );
Input
There are many groups of data, each of which includes two groups of data: a and B.
Output
For each group of data, the return number of all prime numbers (including a and B) that meet the conditions between a and B is output, and a row is left blank after each group of data.
Sample Input
5 500
Sample Output
5
7
11
101
131
151
181
191
313
353
373
383
To be honest, you have to be amazed at others' ideas.
Because the int type occupies four bytes
To avoid space occupation, define the array as the bool type for processing.
[Cpp]
# Include <stdio. h>
# Include <stdio. h>
Using namespace std;
Boolean a [9989900];
Int prime [1005];
Void set ()
{
Int I, j;
For (I = 2; I <= 9989899; I + = 2)
A [I] = true;
For (I = 3; I <= 3161; I ++)
{
If (a [I])
Continue;
For (j = I + I; j <= 9989899; j + = I)
A [j] = true;
}
}
Int huiwen (int n)
{
Int a = 0, B = n;
While (B)
{
Int r = B % 10;
A = a * 10 + r;
B/= 10;
}
If (a = n)
Return 1;
Return 0;
}
Int main ()
{
Int n, m, I, k = 2;
Set ();
Prime [0] = 5;
Prime [1] = 7;
For (I = 11; I <= 9989899; I + = 2)
{
If (! A [I] & huiwen (I ))
Prime [k ++] = I;
}
While (~ Scanf ("% d", & n, & m ))
{
For (I = 0; I <k; I ++)
{
If (prime [I] <n)
Continue;
Else if (prime [I]> m)
Break;
Else
Printf ("% d \ n", prime [I]);
}
Printf ("\ n ");
}
Return 0;
}