-
Notifications
You must be signed in to change notification settings - Fork 0
/
10200_PrimeTime.cpp
85 lines (67 loc) · 1.37 KB
/
10200_PrimeTime.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
using namespace std;
#include<iostream>
#include<cstring>
#include<cstdio>
#define n 10000000
int prime[n];
long long int arr[n],k,i,j;
void primeFIND()
{
k=0;
memset(prime , 0 , sizeof prime);
prime[0]=prime[1]=1;
for(i=2;i<=n;i++)
{
if(!prime[i])
{
for(j=i*i;j<=n;j=j+i)
prime[j]=1;
arr[k++]=i;
}
}
}
int main()
{
long long int a,b,m,cnt,index,idiot;
int flag;
int newer[10000+10];
double ans;
primeFIND();
memset(newer , 0 , sizeof newer);
for(i=0;i<=10000;i++)
{
idiot=i*i+i+41;
if(idiot<n)
{
if(!prime[idiot])
newer[i]=1;
}
else
{
index=flag=1;
while(arr[index]*arr[index]<=idiot)
{
if(idiot % arr[index]==0){
flag=0;
break;
}
index++;
}
if(flag)
newer[i]=1;
}
}
while(cin>>a>>b)
{
cnt=0;
for(m=a;m<=b;m++)
{
if(newer[m])
cnt++;
}
ans=(double)((cnt*100.0)/(double)(b-a+1));
printf("%.2lf\n",ans);
//printf ("%.2lf\n", (cnt * 100.0) / (double)(b - a + 1) + 1e-9);
}
return 0;
}