Cod sursa(job #2902064)
Utilizator | Data | 15 mai 2022 14:11:51 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n, i, j, cnt;
bool ciur[2000001];
int main(){
fin >> n;
ciur[0] = ciur[1] = 1;
for(i = 2; i <= n; i++)
ciur[i] = 1;
for(i = 2; i <= n; i++){
if(ciur[i]){
cnt++;
for(j = 2 * i; j <= n; j += i)
ciur[j] = 0;
}
}
fout << cnt;
}