6 kyu

Sieve of Eratosthenes

103 of 221rojoangel

Description:

Sieve of Eratosthenes

Theoretical introduction

The sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the multiples of 2.

Wikipedia, Sieve of Eratosthenes

Description of the algorithm

The multiples of a given prime are generated as a sequence of numbers starting from that prime, with constant difference between them that is equal to that prime.[1] This is the sieve's key distinction from using trial division to sequentially test each candidate number for divisibility by each prime.[2]

Wikipedia, Sieve of Eratosthenes

A visual representation:

from wikipedia

(Source is Wikimedia Commons, Sieve_of_Eratosthenes_animation)

Problem description

Create a program that is able to calculate all the prime numbers up to a higher bound.

Given that:

The sieve of Eratosthenes is one of the most efficient ways to find all of the smaller primes

Wikipedia, Sieve of Eratosthenes

Samples

primes 5: 2, 3, 5
primes 10: 2, 3, 5, 7
Algorithms

Stats:

CreatedSep 9, 2015
PublishedSep 9, 2015
Warriors Trained419
Total Skips11
Total Code Submissions644
Total Times Completed221
Haskell Completions103
Java Completions120
Total Stars11
% of votes with a positive feedback rating87% of 79
Total "Very Satisfied" Votes62
Total "Somewhat Satisfied" Votes13
Total "Not Satisfied" Votes4
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • rojoangel Avatar
  • smile67 Avatar
  • ParanoidUser Avatar
  • rford Avatar
  • Voile Avatar
Ad