Created
April 30, 2012 18:02
-
-
Save biwakonbu/2560516 to your computer and use it in GitHub Desktop.
Eratosthenes
This file contains 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 FALSE 0 | |
#define TRUE 1 | |
int main (int argc, char* argv[]) | |
{ | |
int i, p, k, count, n; | |
char flag[1000000]; | |
while (scanf("%d", &n) != EOF) { | |
if (2 <= n) { | |
count = 1; | |
} else { | |
count = 0; | |
} | |
for (i=0; i<=n; i++) { | |
flag[i] = TRUE; | |
} | |
for (i=0; i<=n; i++) { | |
if (flag[i]) { | |
p = i + i + 3; | |
printf("%8d\n", p); | |
for (k=i+p; k<=n; k+=p) { | |
flag[k] = FALSE; | |
} | |
if (p <= n) { | |
count++; | |
} | |
} | |
} | |
printf("number %d\n", count); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment