Nyoj-Twin Prime Number Problem

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.