-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPRIME.cpp
69 lines (69 loc) · 1.26 KB
/
CPRIME.cpp
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
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
long int a[60000001];
std::vector <bool> b(100000001,true);
long int Calcprimes ()
{
long int i,j,k,l;
a[0]=2;
k=1;
for (i=3;i<=10000;i+=2)
{
if (b[i]==true)
{
for (j=i*i;j<=100000000;j+=(2*i))
b[j]=false;
}
}
for (j=3;j<=100000000;j+=2)
if (b[j]==true)
a[k++]=j;
return k;
}
long int Binarysearch (long int x,long int e)
{
long int d=0,f=e;
while (d<=e)
{
if (x<a[d])
return d-1;
if (x>a[e])
return e;
long int mid=(d+e)/2;
if (x==a[mid])
return mid;
if (x<a[mid])
e=mid-1;
if (x>a[mid])
d=mid+1;
}
return f;
}
int main()
{
long int x,i,d,e;
double b;
e=Calcprimes();
while (1)
{
scanf ("%ld",&x);
if (x==0)
break;
b=x;
d=Binarysearch(x,e-1);
d++;
b/=(double)log(x);
double c;
if (b>d)
c=b-d;
else
c=d-b;
c=(double)c/d;
c*=100;
printf ("%.1f\n",c);
}
return 0;
}