Prime Sieve (1) Wagered Sieve method

Source: Internet
Author: User

The principle is to first 2-n all the numbers within an array, initialize all the numbers are prime, and then starting from 2 to look for, as long as the mark is a prime number of his all multiples of the mark is changed to composite, and so on. The time complexity is O (NLOGLOGN).

Code implementation

 1  void   Prime_table ()  2  3  for  (int  i=2 ;(LL) i<=n;i++) prime[i]=;  4   int  i=2 ;(LL) i*i<=n;i++)  Span style= "color: #008080;" >5  if  (Prime[i]) for  (LL j=i*i; j<=n;j+=i) Prime[j]=0   6 } 
Prime Sieve

Prime Sieve (1) Wagered Sieve method

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.