- #include <stdio.h>
- #include<stdbool.h>
- int E(int N)
- {
- int i, j;
- bool a[N];
- for (i = 2; i < N; i++)
- {
- a[i] = 1;// true
- }
- for (i = 2; i < N; i++)
- {
- if (a[i])
- {
- for (j = i+i; j < N; j += i)//
- {
- a[j] = 0;
- }
- }
- }
- for (i = 2; i < N; i++)
- {
- if (a[i])
- printf("%d ", i);
- }
- printf("\\n");
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- E(n);
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1004201512203.html
来源: http://www.codesnippet.cn/detail/1004201512203.html