-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10200.cpp
91 lines (76 loc) · 1.71 KB
/
uva10200.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using namespace std;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<math.h>
#define N 11000
#define eps 1e-9
typedef long long int ll_d;
bool prime[N],ans[N];
vector<int>primes;
void sieve()
{
ll_d sq=sqrt(N),i,k;
prime[0]=prime[1]=true;
primes.push_back(2);
for(i=4;i<N;i+=2)
prime[i]=true;
for(i=3;i<=sq;i+=2)
{
if(prime[i]==false)
{
primes.push_back(i);
for(k=i*i;k<N;k+=2*i)
prime[k]=true;
}
}
while(i<N)
{
if(prime[i]==false)
primes.push_back(i);
i+=2;
}
}
ll_d Euler_prime(int n)
{
return (n*n)+n+41;
}
bool prime_check(ll_d n)
{
if(n<N&&prime[n]==false)
return true;
int i,sz=primes.size(),sq=sqrt(n);
for(i=0;i<sz&&primes[i]<=sq;i++)
{
if(n%primes[i]==0)
return false;
}
return true;
}
void calc()
{
for(int i=0;i<10002;i++)
{
ll_d k=Euler_prime(i);
if(prime_check(k))
ans[i]=true;
}
}
int main()
{
int a,b,i,cnt1;
sieve();
calc();
while(scanf("%d%d",&a,&b)==2)
{
cnt1=0;
for(i=a;i<=b;i++)
{
if(ans[i]) cnt1++;
}
//printf("%.2lf\n",(double)((100.0*(double)cnt1)/(double)(b-a+1)));
printf("%.2lf\n",(cnt1*100.0)/((b-a+1)*1.0)+eps);
}
return 0;
}