×

# faster prime generating with seive

 0 I use a seive code for generating primes.I dont know if it is fast enough.If anyone have any idea to make my code faster then please help.Or give me a faster code so I can store that for later use. Thanks in advance. //function sieve begin: #define Max 20000000 int prime_int[Max]; bool prime_bool[Max]; void prime_num() { int i,j,root=sqrt(Max); for(i=4;i<=Max;i+=2) prime_bool[i]=true; for(i=3;i<=root;i+=2) if(!prime_bool[i]) { for(j=i*i;j<=Max;j+=2*i) prime_bool[j]=true; } prime_int[0]=2; for(i=3,j=1;i

 1 here is a fastest method to generate primes.. other methods are sieve of eratosthenes. the second method is easier to understand and implement also :) answered 25 Nov '14, 22:15 779●2●14 accept rate: 14% That code is implement of sieve of eratosthenes (25 Nov '14, 22:29) moudud994★
 0 answered 26 Nov '14, 00:23 1.9k●1●12●43 accept rate: 14% well I can not do python but that list helps.Thanks. (26 Nov '14, 10:41) moudud994★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,917
×1,664
×1,490
×23

question asked: 25 Nov '14, 21:56

question was seen: 800 times

last updated: 26 Nov '14, 10:41