fork download
  1. #include <bits/stdc++.h>
  2. typedef long long int ll;
  3. //typedef unsigned int ul;
  4. void fastscan(ll &x)
  5. {
  6. bool neg=false;
  7. register int c;
  8. x =0;
  9. c=getchar();
  10. if(c=='-')
  11. {
  12. neg = true;
  13. c=getchar();
  14. }
  15. for(;(c>47 && c<58);c=getchar())
  16. x = (x<<1) + (x<<3) +c -48;
  17. if(neg)
  18. x *=-1;
  19. }
  20. using namespace std;
  21. ll arr[50000011];
  22. bool prime[50000011];
  23. int main()
  24. {
  25. ll a,b,c,d,e,f,g,h;
  26. fastscan(a);arr[0]=0;
  27. for(b=1;b<=50000011;b++)
  28. {arr[b] = __builtin_popcount(b) + arr[b-1];}
  29.  
  30. memset(prime,false,sizeof(prime));
  31.  
  32. for(b=2;b<=sqrt(50000011);b++)
  33. {
  34. if(prime[b]==false)
  35. {
  36. for(c=b*2;c<=50000011;c=c+b)
  37. {
  38. prime[c] = true;
  39. }
  40. }
  41. }
  42. for(b=0;b<a;b++)
  43. {
  44. fastscan(c);fastscan(d);
  45. e = arr[d]-arr[c-1];
  46. if(e==1)cout<<"1\n";
  47. else
  48. {
  49. while(1)
  50. {
  51. if(prime[e]==false)
  52. {
  53. cout<<e*2<<"\n";break;
  54. }
  55. else e++;
  56. }
  57. }
  58. }
  59. }
  60.  
Success #stdin #stdout 0.76s 455488KB
stdin
Standard input is empty
stdout
Standard output is empty