Cod sursa(job #1089519)
| Utilizator | Data | 21 ianuarie 2014 19:02:24 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <cstdio>
#define Nmax 2000002
using namespace std;
int n;
int ct = 0;
char pr[Nmax]; // 0 - prim, 1 - neprim
int main()
{
FILE *g = fopen("ciur.in", "r");
fscanf(g, "%d", &n);
fclose(g);
for (int i = 2; i <= n; i++)
if (!pr[i])
{
//printf("%d ", i);
ct++;
for (int j = i+i; j <= n; j += i)
pr[j] = 1;
}
g = fopen("ciur.out", "w");
fprintf(g, "%d", ct);
return 0;
}
