Cod sursa(job #2639422)
| Utilizator | Data | 2 august 2020 00:15:57 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int n;
const int NMAX = 2e6 + 5;
int v[NMAX], nr;
int main()
{
f >> n;
for(int i = 2; i <= n; i++) {
bool ok = 1;
for(int j = 1; j <= nr; j++) {
if(i % v[j] == 0) {
ok = 0;
break;
}
}
if(ok) {
nr++;
v[nr] = i;
}
}
g << nr;
return 0;
}
