fork(5) download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long uint64;
  8.  
  9. int prime(uint64 n)
  10. {
  11. uint64 i=2;
  12. int flag=0;
  13. while(i<=sqrt(n))
  14. {
  15. if(n%i==0)
  16. {
  17. flag=1;
  18. break;
  19. }
  20. i++;
  21. }
  22. if(flag==0)
  23. return 1;
  24. }
  25.  
  26. uint64 prime1(uint64 l,uint64 r)
  27. {
  28. uint64 i,j,z=0,*primes;
  29.  
  30. //primes = malloc(sizeof(int)*limit);
  31. primes= new (nothrow) uint64[r];
  32. for (i=2;i<r;i++)
  33. primes[i]=1;
  34.  
  35. for (i=2;i<r;i++)
  36. if (primes[i])
  37. for (j=i;i*j<r;j++)
  38. primes[i*j]=0;
  39.  
  40. for (i=l;i<r;i++)
  41. if (primes[i])
  42. z++;
  43.  
  44. return z;
  45. }
  46.  
  47. int main()
  48. {
  49. int t,k;
  50. uint64 i,l,r;
  51. scanf("%d",&t);
  52. for(k=0;k<t;k++)
  53. {
  54. scanf("%lld %lld",&l,&r);
  55. long count=0;
  56. if(l==1)
  57. {
  58. l++;
  59. }
  60. if(r==1)
  61. {
  62. r--;
  63. cout<<count;
  64. break;
  65. }
  66. count+=prime1(l,r);
  67. for(i=l;i<=r;i++)
  68. {
  69. double a=sqrt(i);
  70.  
  71. if(a==floor(a))
  72. {
  73. uint64 j=1,c=1;
  74. while(j<a)
  75. {
  76. if(i%j==0)
  77. {
  78. c=c+2;
  79. }
  80. j++;
  81. }
  82. if(prime(c)==1)
  83. {
  84. count++;
  85. }
  86. }
  87. }
  88. cout<<count<<"\n";
  89. }
  90. return 0;
  91. }
Runtime error #stdin #stdout 0s 3752KB
stdin
1
999999000000 1000000000000
stdout
Standard output is empty