首页 > 代码库 > UVA10200 Prime Time

UVA10200 Prime Time

 1 /*
 2  UVA10200 Prime Time 
 3  https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1141
 4  素数 概率论 暴力
 5 
 6  输出的时候加1e-5到1e-14都能过,不加就wa,不是很懂
 7  *
 8  *
 9  *
10  */
11 #include <cstdio>
12 #include <algorithm>
13 #include <cmath>
14 using namespace std;
15 const int Nmax=10001;
16 #define dabiao
17 #ifdef dabiao
18 int f[Nmax];
19 int num[Nmax];
20 int is_prime(long long n)
21 {
22     long long sqr=sqrt(n);
23     for(int i=2;i<=sqr+1;i++)
24         if(n%i==0)
25             return 0;
26     return 1;
27 }
28 
29 inline long long get(long long a)
30 {
31     return a*a+a+41;
32 }
33 
34 int main()
35 {
36     for(int i=0;i<Nmax;i++)
37     {
38         f[i]=is_prime(get(i));
39         if(i==0)
40             num[i]=f[i];
41         else
42             num[i]=f[i]+num[i-1];
43     }
44     int a,b;
45     while(scanf("%d%d",&a,&b)==2)
46     {
47         if(a==0)
48             printf("%.2lf\n",100.0*num[b]*1.0/((b+1)*1.0)+1e-5);
49         else
50             printf("%.2lf\n",100.0*(num[b]*1.0-num[a-1]*1.0)/(b*1.0-a*1.0+1)+1e-5);
51     }
52     return 0;
53 }
54 
55 
56 #endif

 

UVA10200 Prime Time