• Source
    1. #include<bits/stdc++.h>
    2. #define MAX 100010050
    3.  
    4. using namespace std;
    5.  
    6. bool check[MAX];
    7.  
    8. int cum_sum[10005];
    9.  
    10. void sieve()
    11. {
    12. int i,j,k=sqrt(MAX);
    13.  
    14. for(i=41;i<k;i+=2)
    15. {
    16. for(j=i*i;j<MAX;j+=i+i)
    17. {
    18. check[j] = true;
    19. }
    20. }
    21.  
    22. cum_sum[0] = 1;
    23.  
    24. cum_sum[1] = 2;
    25.  
    26. for(i=2;i<=10000;i++)
    27. {
    28. if(!check[(i*i)+i+41])
    29. {
    30. cum_sum[i] = 1;
    31. }
    32.  
    33. cum_sum[i]+=cum_sum[i-1];
    34. }
    35. }
    36.  
    37. int main()
    38. {
    39. sieve();
    40.  
    41. int a,b;
    42.  
    43. double res,store,tot;
    44.  
    45. while(scanf("%d%d",&a,&b)!=EOF)
    46. {
    47. tot = b-a+1;
    48.  
    49. store = cum_sum[b]-cum_sum[a-1];
    50.  
    51. res = (store/tot)*100.0;
    52.  
    53. printf("%.2lf\n",res+1e-7);
    54. }
    55.  
    56. return 0;
    57. }