Printing some primes
#include<bits/stdc++.h>
using namespace std;
#define mx 100001000
int prime[(mx>>6) + 1] , prm[(mx>>1)+9], plen=1;
#define setbit(n) (prime[n>>6] |= (1 << ((n>>1)&31)))
#define checkbit(n) (prime[n>>6] & (1 << ((n>>1)&31)))
typedef long long LL;
LL ans[60000+6];
void sieve()
{
LL i,j;
for(i=3;i*i<=mx; i+=2)
{
if(!checkbit(i))
{
for(j=i*i;j<=mx;j+=i+i)
{
setbit(j);
}
}
}
prm[plen++]=2;
for(i=3;i<=mx;i+=2)
{
if(!checkbit(i))
{
prm[plen++] = i;
}
}
//for(i=0;i<100;i++)cout << prm[i] << " ";
cout << 2 << "\n";
LL trk = 101,cnt=0,len=0;
for(i=2;i<=plen;i++)
{
if(i == trk)
{
ans[len++] = prm[i];
//cout << prm[i] << "\n";
//cnt++;
trk+=100;
}
}
//cout << "cnt = " << cnt;
for(i=0;i<len-1;i++)
{
cout << ans[i] << "\n";
}
}
int main()
{
sieve();
return 0;
}
using namespace std;
#define mx 100001000
int prime[(mx>>6) + 1] , prm[(mx>>1)+9], plen=1;
#define setbit(n) (prime[n>>6] |= (1 << ((n>>1)&31)))
#define checkbit(n) (prime[n>>6] & (1 << ((n>>1)&31)))
typedef long long LL;
LL ans[60000+6];
void sieve()
{
LL i,j;
for(i=3;i*i<=mx; i+=2)
{
if(!checkbit(i))
{
for(j=i*i;j<=mx;j+=i+i)
{
setbit(j);
}
}
}
prm[plen++]=2;
for(i=3;i<=mx;i+=2)
{
if(!checkbit(i))
{
prm[plen++] = i;
}
}
//for(i=0;i<100;i++)cout << prm[i] << " ";
cout << 2 << "\n";
LL trk = 101,cnt=0,len=0;
for(i=2;i<=plen;i++)
{
if(i == trk)
{
ans[len++] = prm[i];
//cout << prm[i] << "\n";
//cnt++;
trk+=100;
}
}
//cout << "cnt = " << cnt;
for(i=0;i<len-1;i++)
{
cout << ans[i] << "\n";
}
}
int main()
{
sieve();
return 0;
}
Comments
Post a Comment