Cod sursa(job #1500706)
| Utilizator | Data | 12 octombrie 2015 16:43:49 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
const int NMax = 2e6 + 5;
int k;
int Prim[NMax];
bool viz[NMax];
void Ciur(int n)
{
for(int i = 2; i <= n; i++)
{
if(viz[i] == 0)
{
k++;
Prim[k] = i;
for(int j = 2*i; j <= n; j = j + i)
{
viz[j] = 1;
}
}
}
}
int main()
{
int n;
f >> n;
Ciur(n);
g << k;
return 0;
}
