Skip to content

Instantly share code, notes, and snippets.

@cwt8805
Created January 14, 2016 03:17
Show Gist options
  • Select an option

  • Save cwt8805/c3905da978610c5addff to your computer and use it in GitHub Desktop.

Select an option

Save cwt8805/c3905da978610c5addff to your computer and use it in GitHub Desktop.
Eratosthenes 算法
#include <stdio.h>
#include <stdlib.h>
#define N 10000
int main()
{
int i, j, a[N];
for (i = 2; i < N; i++) a[i] = 1;
for (i = 2; i < N; i++)
{
if (a[i])
for (j = i; j < N/i; j++)
a[i*j] = 0;
}
for (i = 2; i < N; i++)
if (a[i]) printf("%4d ", i);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment