-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsieveOfEratostenes.c
More file actions
47 lines (43 loc) · 832 Bytes
/
Copy pathsieveOfEratostenes.c
File metadata and controls
47 lines (43 loc) · 832 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
int a[1000001];
/*int isPrime(int n)
{
if(n==1||n==0)
return 0;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
return 0;
}
return 1;
}*/
//sieve of eratostenes is this where if the component of a[i]=1 then "i" is prime else it is not
void seive()
{
int maxN=1000000;
for(int i=2;i<=maxN;i++)
{
a[i]=1; //initiating every number as prime
}
for(int i=2;i*i<=maxN;i++)
{
if(a[i])
{
for(int j=i*i;j<=maxN;j+=i)
{
a[j]=0;//0 represent not prime number every multiple of primes are terminated
}
}
}
}
int main()
{
seive();
int b;
scanf("%d",&b);
if(a[b])
printf("PRIME\n");
else
printf("NOT PRIME\n");
return 0;
}