Click here to Skip to main content
15,891,905 members
Home / Discussions / C#
   

C#

 
AnswerRe: BackUp And Restore of SqlServer 2005 using C# Windows Application Pin
Roger Wright12-Sep-12 20:28
professionalRoger Wright12-Sep-12 20:28 
QuestionFirst real C# program by C++ developer Pin
PapaGeek12-Sep-12 16:27
PapaGeek12-Sep-12 16:27 
AnswerRe: First real C# program by C++ developer Pin
Roger Wright12-Sep-12 20:21
professionalRoger Wright12-Sep-12 20:21 
GeneralRe: First real C# program by C++ developer Pin
BobJanova12-Sep-12 23:07
BobJanova12-Sep-12 23:07 
GeneralRe: First real C# program by C++ developer Pin
jschell13-Sep-12 8:28
jschell13-Sep-12 8:28 
AnswerRe: First real C# program by C++ developer Pin
V.12-Sep-12 20:30
professionalV.12-Sep-12 20:30 
AnswerRe: First real C# program by C++ developer Pin
Richard MacCutchan12-Sep-12 22:26
mveRichard MacCutchan12-Sep-12 22:26 
AnswerRe: First real C# program by C++ developer Pin
jschell13-Sep-12 8:59
jschell13-Sep-12 8:59 
AnswerRe: First real C# program by C++ developer Pin
wizardzz13-Sep-12 10:46
wizardzz13-Sep-12 10:46 
AnswerRe: First real C# program by C++ developer Pin
Alan Balkany13-Sep-12 11:10
Alan Balkany13-Sep-12 11:10 
AnswerRe: First real C# program by C++ developer Pin
Alan Balkany13-Sep-12 11:44
Alan Balkany13-Sep-12 11:44 
QuestionDynamic TimeSlots Pin
Member 941347212-Sep-12 8:34
Member 941347212-Sep-12 8:34 
AnswerRe: Dynamic TimeSlots Pin
Pete O'Hanlon12-Sep-12 9:46
mvePete O'Hanlon12-Sep-12 9:46 
QuestionSieve of Eratosthenes Pin
WebMaster12-Sep-12 4:23
WebMaster12-Sep-12 4:23 
AnswerRe: Sieve of Eratosthenes Pin
fjdiewornncalwe12-Sep-12 4:31
professionalfjdiewornncalwe12-Sep-12 4:31 
AnswerRe: Sieve of Eratosthenes Pin
Manfred Rudolf Bihy12-Sep-12 4:36
professionalManfred Rudolf Bihy12-Sep-12 4:36 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 4:39
WebMaster12-Sep-12 4:39 
GeneralRe: Sieve of Eratosthenes Pin
Manfred Rudolf Bihy12-Sep-12 4:45
professionalManfred Rudolf Bihy12-Sep-12 4:45 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 4:56
WebMaster12-Sep-12 4:56 
GeneralRe: Sieve of Eratosthenes Pin
Manfred Rudolf Bihy12-Sep-12 5:04
professionalManfred Rudolf Bihy12-Sep-12 5:04 
GeneralRe: Sieve of Eratosthenes Pin
Richard MacCutchan12-Sep-12 5:40
mveRichard MacCutchan12-Sep-12 5:40 
AnswerRe: Sieve of Eratosthenes PinPopular
J4amieC12-Sep-12 4:53
J4amieC12-Sep-12 4:53 
According to wiki[^]

"The sieve of Eratosthenes is one of the most efficient ways to find all of the smaller primes (below 10 million or so)." (Citation: The Prime Glossary: "The Sieve of Eratosthenes", http://primes.utm.edu/glossary/page.php?sort=SieveOfEratosthenes, references 16. November 2008.)

That should answer your question; The algo is good for the range of numbes you've chosen.

However (and thats a BIG however), your implementation is wrong.

for i = 2, 3, 4, ..., √n :
  if A[i] is true:
    for j = i2, i2+i, i2+2i, ..., n:
      A[j] := false


You've forgotton to only go to the square root of n (Think about why its only necessary to go to sqrt of n!), which takes a HUGE chunk off of the processing. Also, there should be no second if, in that part of the code, you've already multiplied 2 numbers together, so you know the result cannot be prime.

All in all, youve implemented brute force, which is miles slower than the Sieve of Eratosthenesfor finding primes.
AnswerRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 4:54
mvePete 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 

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.