• Source
    1. #include<bits/stdc++.h>
    2. #define MAX 5000009
    3.  
    4. using namespace std;
    5.  
    6. bool check[MAX];
    7.  
    8. int sum_of_factors[MAX],DePrimes[MAX];
    9.  
    10. void solve()
    11. {
    12. int i,j;
    13.  
    14. for(i=4;i<MAX;i+=2)
    15. {
    16. sum_of_factors[i]+=2;
    17.  
    18. check[i] = true;
    19. }
    20.  
    21. for(i=3;i<=2238;i+=2)
    22. {
    23. if(!check[i])
    24. {
    25. for(j=i*i;j<=MAX;j+=i+i)
    26. {
    27. check[j] = true;
    28. }
    29. }
    30. }
    31.  
    32. for(i=3;i<MAX;i+=2)
    33. {
    34. if(!check[i])
    35. {
    36. for(j=i;j<=MAX;j+=i)
    37. {
    38. sum_of_factors[j]+=i;
    39. }
    40. }
    41. }
    42.  
    43. DePrimes[0]=DePrimes[1]=0;
    44.  
    45. sum_of_factors[2] = 2;
    46.  
    47. for(i=2;i<MAX;i++)
    48. {
    49. if(!check[sum_of_factors[i]])
    50. {
    51. DePrimes[i] = 1;
    52. }
    53.  
    54. DePrimes[i]+=DePrimes[i-1];
    55. }
    56. }
    57.  
    58.  
    59. int main()
    60. {
    61. solve();
    62.  
    63. int a,b;
    64.  
    65. while(scanf("%d",&a)&&a)
    66. {
    67. scanf("%d",&b);
    68.  
    69. printf("%d\n",DePrimes[b]-DePrimes[a-1]);
    70. }
    71.  
    72. return 0;
    73. }