Cod sursa(job #1952608)
Utilizator | Data | 4 aprilie 2017 11:29:35 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
int n, nr = 1;
int OK[2000010];
int main()
{
in >> n;
for (int i = 3; i <= n; i = i + 2)
{
if (OK[i] == 0)
{
for (unsigned long long j = i * i; j <= n; j = j + i)
OK[j] = 1;
OK[i] = 1;
nr++;
}
}
out << nr;
return 0;
}