Created
February 10, 2015 20:48
-
-
Save eroltutumlu/d1c1eb66183b996bfaad to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define SIZE 1000000 | |
int main(void) { | |
long long int i,j; | |
int *primes; | |
primes = malloc(sizeof(int)*SIZE); | |
for(i = 2; i < SIZE; i++) | |
{ | |
primes[i] = 1; | |
} | |
for(i = 2; i < SIZE; i++) | |
{ | |
for(j = i; i*j < SIZE; j++) | |
{ | |
if(primes[i]) | |
{ | |
primes[i*j] = 0; | |
} | |
} | |
} | |
for(i = 2; i < SIZE; i++) | |
{ | |
if(primes[i]) | |
{ | |
printf("%llu ",i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment