-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCPRIME_re.cpp
More file actions
77 lines (75 loc) · 1.61 KB
/
CPRIME_re.cpp
File metadata and controls
77 lines (75 loc) · 1.61 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <cstdio>
#include<cmath>
#include<map>
#include<cstring>
#define max 32000
using namespace std;
long int cntr=0;
bool *p=new bool[max];
map <long int,long int> mapi;
//int array[10000007]={0};
void sieve(){
int i,j;
memset(p,true,(sizeof(bool)*max));
for(i=2;i<(max);++i)
{
if(p[i]){
for(j=2*i;j<max;j+=i)
p[j]=false;
}
}
}
int prime[max];
int calprime(){
int i,k=0;
for(i=2;i<(max);++i)
{
if(p[i]){
prime[k]=i;
k++;
}
}
return k;
}
int cntr2=0;
int main() {
int i,t,no_prime,flag;
sieve();
no_prime=calprime();
long int m,n,x;
while(true)
{
n=10000000;
if(mapi[n]!=0){cntr=mapi[n];goto there;}
//if(array[n]!=0){cntr=array[n];goto there;}
for(x=2;x<=n;++x)
{
flag=1;
for(i=0;prime[i]<=sqrt(x)&&i<no_prime;++i)
{
if(x%prime[i]==0)
{
flag=0;
break;
}
}
if(flag&&x>1){
//printf("%ld\n",x);
cntr++;}
mapi[x]=cntr;
//array[x]=cntr;
}
there:
if(cntr2!=0){
double f=n/log(n);
double result=((cntr-f)/cntr)*100;
if(result<0)result*=-1;
printf("%0.1lf\n",result);
//printf("cnttr:%d\n",cntr);
cntr=0;}
cntr2++;
scanf("%ld",&n);
if(n==0)return 0;
}
return 0;
}