fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. #define MAX 1000000
  6. int snt[MAX+10];
  7. int mcd[MAX+10];
  8.  
  9. int sont(int n)
  10. {
  11. if (n<2)
  12. return 0;
  13. for (int i=2; i<=sqrt(n); i++)
  14. {
  15. if (n%i==0)
  16. {
  17. return 0;
  18. }
  19. }
  20. return 1;
  21. }
  22.  
  23. void init()
  24. {
  25. for (int i=1; i<=MAX; i++)
  26. {
  27. snt[i] = 1;
  28. mcd[i] = 0;
  29. }
  30. }
  31.  
  32. void sangnt()
  33. {
  34. snt[0] = 0;
  35. snt[1] = 0;
  36. for (int i=2; i<=sqrt(MAX); i++)
  37. {
  38. if (snt[i] == 1)
  39. {
  40. for (int j=2; j<=MAX/i; j++)
  41. {
  42. snt[i*j] = 0;
  43. }
  44. }
  45. }
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51. init();
  52. sangnt();
  53. int t;
  54. cin>>t;
  55. while(t--)
  56. {
  57. int a, b;
  58. cin>>a>>b;
  59. int ts = 0;
  60. for (int i=a; i<=b; i++)
  61. {
  62. if (snt[i]==1 && snt[i+6]==1 && i+6<=b)
  63. {
  64. ts ++;
  65. }
  66. }
  67. cout<<ts<<endl;
  68. }
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 11308KB
stdin
3
11 19
6 59
2 1000000
stdout
2
10
16386