Cod sursa(job #2098169)
Utilizator | Data | 2 ianuarie 2018 14:54:28 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 40 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int n;
bool v[1000005];
int main()
{
f >> n;
v[1] = 1;
for(int i = 2; i < n; ++i)
{
if(!v[i])
for(int j = 2; i*j <= n; ++j)
v[i*j] = 1;
}
int nr = 0;
for(int i = 1; i <= n; ++i)
if(!v[i]) ++nr;
g <<nr;
}