fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. // Input macros
  4. #define MOD_mini 1000007
  5. #define s(n) scanf("%d",&n)
  6. #define sc(n) scanf("%c",&n)
  7. #define sl(n) scanf("%lld",&n)
  8. #define sf(n) scanf("%lf",&n)
  9. #define ss(n) scanf("%s",n)
  10. // Useful constants
  11. #define INF (int)1e9
  12. #define EPS 1e-9
  13. // Useful hardware instructions
  14. #define bitcount __builtin_popcount
  15. #define gcd __gcd
  16. // Useful container manipulation / traversal macros
  17. #define forall(i,a,b) for(int i=a;i<b;i++)
  18. #define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
  19. #define all(a) a.begin(), a.end()
  20. #define in(a,b) ( (b).find(a) != (b).end())
  21. #define pb push_back
  22. #define fill(a,v) memset(a, v, sizeof a)
  23. #define sz(a) ((int)(a.size()))
  24. #define mp make_pair
  25. // Some common useful functions
  26. #define maX(a,b) ( (a) > (b) ? (a) : (b))
  27. #define miN(a,b) ( (a) < (b) ? (a) : (b))
  28. #define checkbit(n,b) ( (n >> b) & 1)
  29. #define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end())
  30. #define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
  31.  
  32. typedef pair<int,int> ii;
  33. typedef vector<int> vi;
  34. typedef vector<long> vl;
  35. #include<bits/stdc++.h>
  36. using namespace std;
  37. // Input macros
  38. #define s(n) scanf("%d",&n)
  39. #define sc(n) scanf("%c",&n)
  40. #define sl(n) scanf("%lld",&n)
  41. #define sf(n) scanf("%lf",&n)
  42. #define ss(n) scanf("%s",n)
  43. // Useful constants
  44. #define INF (int)1e9
  45. #define EPS 1e-9
  46. // Useful hardware instructions
  47. #define bitcount __builtin_popcount
  48. #define gcd __gcd
  49. // Useful container manipulation / traversal macros
  50. #define forall(i,a,b) for(int i=a;i<b;i++)
  51. #define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
  52. #define all(a) a.begin(), a.end()
  53. #define in(a,b) ( (b).find(a) != (b).end())
  54. #define pb push_back
  55. #define fill(a,v) memset(a, v, sizeof a)
  56. #define sz(a) ((int)(a.size()))
  57. #define mp make_pair
  58. // Some common useful functions
  59. #define maX(a,b) ( (a) > (b) ? (a) : (b))
  60. #define miN(a,b) ( (a) < (b) ? (a) : (b))
  61. #define checkbit(n,b) ( (n >> b) & 1)
  62. #define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end())
  63. #define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin())
  64.  
  65. typedef pair<int,int> ii;
  66. typedef vector<int> vi;
  67. typedef vector<long> vl;
  68.  
  69. vector<bool> prime(31623,true);
  70. vector<int> primes_list;
  71. int main()
  72. {
  73. int i,j,t,k;
  74. long a,b,m,n,p;;
  75. for(i=3;i<=31623;i=i+2)
  76. {
  77. if(prime[i])
  78. {
  79. for(j=2*i;j<=31623;j=j+i)
  80. {
  81. if(prime[j])
  82. {
  83. prime[j] = false;
  84. }
  85. }
  86. }
  87. }
  88. primes_list.push_back(2);
  89. for(i=3;i<=31622;i=i+2)
  90. {
  91. if(prime[i])
  92. {
  93. primes_list.push_back(i);
  94. //printf("%d ",i);
  95. }
  96. }
  97. //for(i=0;i<primes_list.size();i++)
  98. //printf("%d ",primes_list[i]);
  99. scanf("%d",&t);
  100. for(k=0;k<t;k++)
  101. {
  102. //printf("1\n");
  103. scanf("%ld %ld",&a,&b);
  104. vector<bool> matrix(100005,true);
  105. n = sqrt((double)b);
  106. //printf("%ld\n",n);
  107. for(i=0;primes_list[i]<=n;i++)
  108. {
  109. p = a/primes_list[i];
  110. m=p*primes_list[i];
  111. if(m==0) m=2*primes_list[i];
  112. else if(m<a) m+=primes_list[i];
  113. //printf("%ld\n",p);
  114.  
  115. for(;m<=b;m+=primes_list[i])
  116. {
  117. matrix[m-a]= false;
  118. //printf("%ld ",m);
  119. }
  120. }
  121. for(i=0;i<=(b-a);i++)
  122. {
  123. if(matrix[i]&&((i+a)!=1))
  124. printf("%ld\n",i+a);
  125. }
  126. printf("\n");
  127. }
  128.  
  129.  
  130. return 0;
  131. }
  132.  
  133.  
Success #stdin #stdout 0s 3420KB
stdin
3
1 10
3 5
100 300
stdout
2
3
5
7

3
5

101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277
281
283
293