Cod sursa(job #1189229)
| Utilizator | Data | 21 mai 2014 21:14:13 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.38 kb |
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
int n, nrp; bool P[2000001];
int main(){
int i, j;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
scanf("%d", &n); nrp = n - 1;
for (i = 2; i <= n; i++){
if (!P[i]){
for (j = 2 * i; j <= n; j += i){
nrp -= 1 - P[j];
P[j] = 1;
}
}
}
printf("%d", nrp);
return 0;
}