Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 4:53
J4amieC12-Sep-12 4:53 
AnswerRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 4:54
subeditorPete O'Hanlon12-Sep-12 4:54 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 4:59
WebMaster12-Sep-12 4:59 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:02
J4amieC12-Sep-12 5:02 
GeneralRe: Sieve of Eratosthenes Pin
Manfred Rudolf Bihy12-Sep-12 5:06
professionalManfred Rudolf Bihy12-Sep-12 5:06 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:07
J4amieC12-Sep-12 5:07 
GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 5:04
subeditorPete O'Hanlon12-Sep-12 5:04 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 5:16
WebMaster12-Sep-12 5:16 
What have you to say?
I guess you can't collate the code and algorithm, so I help you by this:
C#
//1. Create a list of consecutive integers from 2 to n: (2, 3, 4, ..., n).
List<int> numbers = new List<int>();
for (int i = 2; i < 2000000; i++)
    numbers.Add(i);

//2. Initially, let p equal 2, the first prime number.
for (int p = 0; p < numbers.Count - 1; p++)
   if (numbers[p].IsPrime)
      for (int j = p + 1; j < numbers.Count - 1; j++)
          //note that some of them may have already been marked.
          if (numbers[p].IsPrime)
          //3. Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list. These numbers will be 2p, 3p, 4p, etc
              if (numbers[j].Value % numbers[p].Value == 0)
                  numbers[j].IsPrime = false;

Meysam


modified 12-Sep-12 14:43pm.

GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 5:22
subeditorPete O'Hanlon12-Sep-12 5:22 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:23
J4amieC12-Sep-12 5:23 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 5:48
WebMaster12-Sep-12 5:48 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:59
J4amieC12-Sep-12 5:59 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 6:11
WebMaster12-Sep-12 6:11 
GeneralRe: Sieve of Eratosthenes Pin
Rage12-Sep-12 6:23
professionalRage12-Sep-12 6:23 
GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 6:25
subeditorPete O'Hanlon12-Sep-12 6:25 
AnswerProper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 10:45
Clifford Nelson12-Sep-12 10:45 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
WebMaster12-Sep-12 11:00
WebMaster12-Sep-12 11:00 
AnswerRe: Proper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 11:20
Clifford Nelson12-Sep-12 11:20 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Dave Kreskowiak12-Sep-12 12:44
mveDave Kreskowiak12-Sep-12 12:44 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 13:07
Clifford Nelson12-Sep-12 13:07 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Dave Kreskowiak12-Sep-12 18:25
mveDave Kreskowiak12-Sep-12 18:25 
AnswerRe: Sieve of Eratosthenes Pin
Thomas Daniels12-Sep-12 5:29
mentorThomas Daniels12-Sep-12 5:29 
AnswerRe: Sieve of Eratosthenes Pin
Kenneth Haugland13-Sep-12 3:33
mvaKenneth Haugland13-Sep-12 3:33 
AnswerRe: Sieve of Eratosthenes Pin
PIEBALDconsult12-Sep-12 14:23
mvePIEBALDconsult12-Sep-12 14:23 
QuestionSubstitution of Paths in HyperLinkField with File Names Pin
ASPnoob12-Sep-12 4:23
ASPnoob12-Sep-12 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.