Cod sursa(job #2479335)
| Utilizator | Data | 23 octombrie 2019 18:16:11 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include<stdio.h>
#include<algorithm>
using namespace std;
#define NMAX 2000003
bool v[NMAX + 5];
int main () {
// freopen("ciur.in", "r", stdin);
// freopen("ciur.out", "w", stdout);
int n, cnt;
cnt = 0;
scanf("%d", &n);
for(int i = 2; i <= n; i++) {
if (v[i] == 0) {
// printf("%d\n", i);
for(long long j = (long long)i * i; j <= n; j += i)
v[j] = 1;
}
}
//return 0;
for(int i = 2; i <= n; i++) {
if(v[i] == 0)
cnt++;
}
printf("%d", cnt);
return 0;
}
