Cod sursa(job #872306)
Utilizator | Data | 5 februarie 2013 22:33:26 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
bool v[2000001];
int N;
int ct;
int main()
{
f >> N;
for(int i = 2; i <= N; i++) {
v[i] = 1;
}
for(int i = 2; i <= N; i++) {
if(v[i] == 1) {
ct++;
for(int j = i + i; j <= N; j += i) {
v[j] = 0;
}
}
}
g << ct;
}