C Language > Construction Prime number Table

Source: Internet
Author: User

1#include <stdio.h>2 #defineNumber 10003 4 intMain () {5     intIsprime[number];6      for(inti =0; I < number; i++){7Isprime[i] =1;8     }9     intx =2;Ten      while(X <Number ) { One         if(Isprime[x]) { A              for(inti =2; X*i < number; i++){ -Isprime[x*i] =0; -             } the         } -X + +; -     } -      for(inti =2; I < number; i++){ +         if(Isprime[i]) { -printf"%d\t", i); +         } A     } at     return 0; -}

List of construction primes
To construct a list of primes within n (not included)
1. Open Prime[n], initialize all its elements to 1,prime[x] to 1, table? x is the prime number
2. Make x=2
3. If x is a prime number, then for (i=2;x*i<n;i++) Order prime[i*x]=0
4. Make x + +, if x<n, repeat 3, otherwise end

C Language > Construction Prime number Table

Related Article

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.