include cmath include cstdio include cstdlib void erat long long long

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <cmath>
#include <cstdio>
#include <cstdlib>
void erat(long long m, long long n)
{
if (n<m) {int t=m; m=n; n=t; }
int res[n-m];
for (int i=0; i<n-m; i++) res[i]=1;
for (int x=2; x<ceil(sqrt(n)); x++)
{
long long num = 2*x;
if (num<m) num += (int)ceil(((float)(m-num)/(float)x))*x;
for (;num<n; num+=x)
if ((num-m)<(n-m))
res[num-m] = 0;
}
for (int x=0; x<(n-m); x++)
if (res[x]) printf("%lld\n",m+x);
}
int main()
{
int cases;
scanf("%d\n",&cases);
while (cases--)
{
long long m,n;
scanf("%lld %lld\n",&n,&m);
if (n<2) n=2;
erat(n,m+1);
printf("\n");
}
}