Cod sursa(job #1500718)
| Utilizator | Data | 12 octombrie 2015 16:51:16 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
using namespace std;
int k;
bool viz[2000005];
void ciur(int n)
{
k = 1;
for (int i = 4; i <= n; i = i + 2)
{
viz[i] = 1;
}
for (int i = 3; i <= n; i = i + 2)
{
if(viz[i] == 0)
{
k++;
for (int j = 3 * i; j <= n; j = j + (2 * i))
{
viz[j] = 1;
}
}
}
}
int main()
{
int n;
ifstream f ("ciur.in");
ofstream g ("ciur.out");
f >> n;
ciur(n);
g << k;
return 0;
}
