1 / 11

Sieve of Eratosthenes short demonstration

Sieve of Eratosthenes short demonstration. current prime. square of current prime. confirmed primes. p. current prime. square of current prime. confirmed primes. p. current prime. square of current prime. confirmed primes. p. current prime. square of current prime. confirmed primes.

haroun
Download Presentation

Sieve of Eratosthenes short demonstration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sieve of Eratosthenes short demonstration

  2. current prime square of current prime confirmed primes p

  3. current prime square of current prime confirmed primes p

  4. current prime square of current prime confirmed primes p

  5. current prime square of current prime confirmed primes p

  6. current prime square of current prime confirmed primes p

  7. current prime square of current prime confirmed primes p

  8. current prime square of current prime confirmed primes p

  9. current prime square of current prime confirmed primes p

  10. All white cells up to next prime 23 squared are also primes.

  11. // detect primes up to n std::vector<bool> makePrimes(int n) { std::vector<bool> primes(n+1, true); primes[0] = primes[1] = false; intmul_p; for(intp = 2; p <= (int) sqrt(n); p++) { if(primes[p]) { mul_p = p*p; while(mul_p <= n) { primes[mul_p] = false; mul_p += p; } } } returnprimes; } N loops 100.........104 1000........1411 10000.......16981 100000......193078 1000000.....2122048 10000000....22850051 100000000...242570204 n ~ n*(ln(ln(n)) Sieve of Eratosthenes code and its complexity

More Related