Pagini recente » Cod sursa (job #617165) | Cod sursa (job #2358652) | Cod sursa (job #90321) | Cod sursa (job #2602130) | Cod sursa (job #2760910)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
//Sieve of Eratosthenes:
//Documentation: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
//Problem: https://infoarena.ro/problema/ciur
int main()
{
//Intializations:
int N; // the number greater than all primes.
f >> N;
int intPrimes[N+1];
for(int i=0; i<=N; i++){
intPrimes[i] = 1;
}
intPrimes[0] = 0; intPrimes[1] = 0;
//Sieve filling:
//Compute number of primes.
int numberOfPrimes = 0;
for(int i=2; i*i<=N; i++){
if (intPrimes[i] == 0){continue;}
numberOfPrimes++;
for(int j=i*i; j<=N; j=j+i){
intPrimes[j] = 0;
//if(intPrimes[j] == )
}
}
//for(int i=2; i<=N; i++){
// numberOfPrimes += intPrimes[i];
//cout<<intPrimes[i]<<" ";
//}
g << numberOfPrimes;
return 0;
}