-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprime_serial_soe.c
More file actions
57 lines (47 loc) · 890 Bytes
/
Copy pathprime_serial_soe.c
File metadata and controls
57 lines (47 loc) · 890 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
48
49
50
51
52
53
54
55
56
57
/*
* =====================================================================================
*
* Filename: prime_op.c
*
* Description:
*
* Version: 1.0
* Created: Wednesday 28 May 2014 04:49:52 IST
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include<stdio.h>
#include<math.h>
#include<omp.h>
#define N 5000000
int n=10000001;
int a[N];
void mark(int i)
{int j;
//printf("%d ------\n",i);
for(j=i*i;j<=n-1;j+=2*i)
{//printf("%d ",j);
a[j/2]=1;
}
}
int main()
{int i;
//for(i=0;i<=1000;i++){
//printf("%d ",a[i]);
//}
//printf("%d")
int cnt=1;
for(i=3;i<=sqrt(n-1);i+=2)
{ if (a[i/2]==0)
mark(i);
}
for(i=1;i<=(n-1)/2;i++){
if (a[i]==0){cnt++;
}}
printf("%d",cnt);
}