Twin Prime Number Problem time limit: 3000 MS | memory limit: 65535 kb difficulty: 3
-
Description
-
Write a program to find the number of groups of all the twins in the prime number range. In general, the twin prime number refers to an adjacent prime number that is near two prime numbers and cannot be near any more. Some children's shoes start to write programs as soon as they see the questions and do not read the questions carefully. In order to prevent the children's shoes that are not carefully read the questions, it is stipulated that the two prime numbers adjacent to 1 will also become the twin prime numbers.
-
Input
-
N (0 <n <100) indicates the number of test data groups.
The next group of test data is given m, indicating to find all the twin prime numbers before M.
(0 <m <1000000)
-
Output
-
The output of each group of test data occupies one row, and the number of all twin prime groups in the m range of this behavior.
-
Sample Input
-
114
-
Sample output
-
4
-
Code:
# Include <stdio. h> int f [1000010] = {1000000}; // The memory cannot open. It needs to be larger, otherwise, runtime error !!!!!!!!!!!!!!!! Int s [1000010]; bool is_prime (int n) {int I; for (I = 2; I <n; ++ I) if (N % I = 0) return false; return true;} int main () {int I, j; for (I = 2; I * I <1000010; ++ I) {If (is_prime (I) {f [I] = 0; For (j = I * I; j <1000010; j + = I) f [J] = 1 ;}}for (I = 0, j = 0; I <1000010; ++ I) if (! F [I]) s [J ++] = I; int n, m; scanf ("% d", & N); While (n --) {int K = 0; scanf ("% d", & M); for (I = 1; s [I] <= m; ++ I) if (s [I]-s [I-1] = 1 | s [I]-s [I-1] = 2) K ++; printf ("% d \ n", k);} return 0 ;}
Nyoj-Twin Prime Number Problem