#include<bits/stdc++.h>
using namespace std;
long long int a[10000000], p[1000000];
long long int c;
int main()
{
unsigned long long int n, m, x, y, i, j, v, b;
cin >> n >> m;
x = sqrt(m);
y = sqrt(x);
a[1] = 1;
p[c++] = 2;
for(i=4;i<=x;i+=2)
a[i] = 1;
for(i=3;i<=x;i+=2)
{
if(a[i] != 1)
{
p[c++] = i;
if(i<=y)
{
for(j=i*i;j<=x;j=j+i*2)
{
a[j] = 1;
}
}
}
}
long long int bp[m-n+2];
for(i=0;i<=m-n;i++)
bp[i] = 0;
if(n == 1)
bp[0] = 1;
for(i=0;i<c;i++)
{
v = p[i];
b = v*v;
if(b < n)
b = (((n+v-1)/v)*v);
for(j=b;j<=m;j+=v)
bp[j-n] = 1;
}
for(i=0;i<=m-n;i++)
{
if(bp[i] == 0)
cout << i+n << " ";
}
cout << endl;
return 0;
}
using namespace std;
long long int a[10000000], p[1000000];
long long int c;
int main()
{
unsigned long long int n, m, x, y, i, j, v, b;
cin >> n >> m;
x = sqrt(m);
y = sqrt(x);
a[1] = 1;
p[c++] = 2;
for(i=4;i<=x;i+=2)
a[i] = 1;
for(i=3;i<=x;i+=2)
{
if(a[i] != 1)
{
p[c++] = i;
if(i<=y)
{
for(j=i*i;j<=x;j=j+i*2)
{
a[j] = 1;
}
}
}
}
long long int bp[m-n+2];
for(i=0;i<=m-n;i++)
bp[i] = 0;
if(n == 1)
bp[0] = 1;
for(i=0;i<c;i++)
{
v = p[i];
b = v*v;
if(b < n)
b = (((n+v-1)/v)*v);
for(j=b;j<=m;j+=v)
bp[j-n] = 1;
}
for(i=0;i<=m-n;i++)
{
if(bp[i] == 0)
cout << i+n << " ";
}
cout << endl;
return 0;
}
Comments
Post a Comment