Cod sursa(job #1343284)
| Utilizator | Data | 15 februarie 2015 09:59:25 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <stdio.h>
using namespace std;
bool a[2000000];
int main() {
FILE*in = fopen("ciur.in", "r"); FILE*out = fopen("ciur.out", "w");
int n, contor;
fscanf(in, "%d", &n);
contor = n-1;
for ( int i = 2; i <= n; i++ )
for ( int j = i*i; j <= n; j += i ) {
if ( a[j] == false ) {
a[j] = true;
contor--;
printf("%d \n", j);
}
}
fprintf(out, "%d", contor);
return 0;
}
