Q 1084: Use the sieve method to find the prime numbers in N
Time limit: 1Sec Memory Limit: 128MB
Title Description
Use the sieve method to find the prime numbers in N.
N
Output
The prime numbers from 0 to N
Sample Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
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
|
C Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#include<stdio.h>
int main()
{
int n,i,j,k;
scanf("%d",&n);
for(i=2;i<=n;i++)
{
k=1;
for(j=2;j<i;j++)
{
if(i%j == 0)
k=0;
}
if(k==1)
printf("%d\n",i);
}
int vio;
scanf("%d",&vio);
return 0;
}
|