Twin Prime Number Problem time limit: 3000 MS | memory limit: 65535 KB difficulty: 3 Description to write a program, find out all the twin prime number within the prime number range of the number of groups. 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. Enter N (0 <N <100) in the first line to indicate 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 each group of test data output occupies one row, the number of all the twins in the m range. Sample input 114 sample output 4 [cpp]/**************************** * ***** Date: * Author: SJF0115 * question: Nanyang tech question 26: Twin Prime Number Problem * Source: http://acm.nyist.net/JudgeOnline/problem.php? Pid = 26 * result: AC * Source: * conclusion: * *********************************/# include <stdio. h> # include <math. h> int prime [1000001]; // prime number table int Primes (int n) {int I, j; for (I = 1; I <= n; I ++) {// even if (I % 2 = 0) {prime [I] = 0 ;}// odd else {prime [I] = 1 ;}} // The multiples of odd numbers are certainly not prime numbers for (I = 3; I <= sqrt (n); I + = 2) {if (prime [I]) {for (j = I + I; j <= n; j + = I) {prime [j] = 0 ;}} return 0 ;}int main () {int N, M, count, I; while (scanf (" % D ", & N )! = EOF) {while (N --) {count = 0; scanf ("% d", & M); // evaluate the Susu Primes (M ); // calculate the twin prime number for (I = 2; I <= M-2; I ++) {if (prime [I] & prime [I + 2]) {count ++; // printf ("% d \ n", I, I + 2) ;}// the two prime numbers adjacent to 1 also become twin prime numbers. In this case, only 2, 3 if (M> = 3) {count ++;} printf ("% d \ n", count) ;}} return 0 ;} /********************************** Date: * Author: SJF0115 * question: Nanyang tech question 26: Twin Prime Number Problem * Source: http://acm.nyist.net/JudgeOnline/problem.php? Pid = 26 * result: AC * Source: * conclusion: * *********************************/# include <stdio. h> # include <math. h> int prime [1000001]; // prime number table int Primes (int n) {int I, j; for (I = 1; I <= n; I ++) {// even if (I % 2 = 0) {prime [I] = 0 ;}// odd else {prime [I] = 1 ;}} // The multiples of odd numbers are certainly not prime numbers for (I = 3; I <= sqrt (n); I + = 2) {if (prime [I]) {for (j = I + I; j <= n; j + = I) {prime [j] = 0 ;}} return 0 ;}int main () {int N, M, count, I; while (scanf ("% d", & N )! = EOF) {while (N --) {count = 0; scanf ("% d", & M); // evaluate the Susu Primes (M ); // calculate the twin prime number for (I = 2; I <= M-2; I ++) {if (prime [I] & prime [I + 2]) {count ++; // printf ("% d \ n", I, I + 2) ;}// the two prime numbers adjacent to 1 also become twin prime numbers. There is only one such case 2, 3if (M> = 3) {count ++;} printf ("% d \ n", count) ;}} return 0 ;} note: The next group of test data is given m, indicating to find all the twin prime numbers before m. But it actually includes m. Test Case: m = 7 twin prime number: 2, 3, 5, 5, 7