Cod sursa(job #2378762)
| Utilizator | Data | 12 martie 2019 16:45:26 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
#include <math.h>
#define MAX 2000010
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
int A[MAX];
void SieveOfErathostene(int p) {
for(int i = 1; i <p; i++)
A[i] = 1;
for(int i = 2; i < sqrt(p); i++)
if(A[i])
for(int j = i * i; j <p; j = j + i)
A[j] = 0;
}
int main() {
int n, k = 0;
in >> n;
SieveOfErathostene(n+1);
for(int i = 2; i <= n; i++)
if(A[i])
k++;
out << k;
return 0;
}
