Sgu 231. Prime sum prime number table

Source: Internet
Author: User

Pay special attention to this question: time limit per test: 0.5 sec. Memory
Limit per test: 4096 kb, so pay special attention to constructing a prime number table and marking an array.

# Include <cstdio> # include <cstring> # include <iostream> using namespace STD; int isprime (int n) {for (INT I = 2; I * I <= N; I ++) if (N % I = 0) return 0; return 1 ;}int main () {int COUNT = 0; int N; // while (scanf ("% d", & N )! = EOF) // in the question, the input has only one number, so the write Will PE scanf ("% d", & N); {bool prime [n + 1]; // use int to exceed the memory. // For (INT I = 0; I <= N & I <2; I ++) // prime [I] = false; /* For (INT I = 2; I <= N; I ++) {Prime [I] = false; If (isprime (I )) // this way, the construction of the prime number table will time out prime [I] = true;} */For (INT I = 0; I <= N; I ++) {if (I = 0 | I = 1) prime [I] = false; else Prime [I] = true ;}for (INT I = 2; I * I <= N; I ++) {for (Int J = I; I * j <= N; j ++) {Prime [I * j] = false ;}// learn this method to construct a prime number table // For (INT I = 0; I <= N; I ++) // If (prime [I]) // cout <I <Endl; For (INT I = 0; I <n; I ++) {If (2 + I <= N & prime [I] & prime [I + 2]) Count ++;} cout <count; If (count) for (INT I = 0; I <n; I ++) {If (2 + I <= N & prime [I] & prime [I + 2]) cout <"" <"2" <"" <I;} cout <Endl;} return 0 ;}

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.