Description
用筛法求之N内的素数。
Input
N (0 < N <= 150)
Output
0~N的素数
Sample Input 
100
Sample Output
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,n,a[101];
for(i=1;i<=100;i++)
a[i]=i;
a[1]=0;
for(i=2;i<sqrt(100);i++)
for(j=i+1;j<=100;j++)
{
if(a[i]!=0&&a[j]!=0)
if(a[j]%a[i]==0)
a[j]=0;
}
printf("\n");
for(i=2,n=0;i<=100;i++)
{
if(a[i]!=0)
{
printf("%d\n",a[i]);
n++;
}
}
printf("\n");
return 0;
}
更多关于筛法求素数的算法https://blog.youkuaiyun.com/liamleec/article/details/78524039

1273

被折叠的 条评论
为什么被折叠?



