Cod sursa(job #1283016)
Utilizator | Data | 4 decembrie 2014 23:14:44 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
unsigned char ciur[100000];
int x, i, j;
cin >> x;
memset(ciur, 0, sizeof(ciur));
for(i = 2; i <= x; i++)
{
if(!((ciur[i >> 3] >> i % 8) & 1))
{
cout << i << " ";
for(j = i << 1; j <= x; j += i)
{
ciur[j >> 3] |= 1 << j % 8;
}
}
}
return 0;
}