Cod sursa(job #1247407)
Utilizator | Data | 22 octombrie 2014 18:50:13 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <fstream>
using namespace std;
bool ciur[2000000], c=0;
int main()
{
ifstream f("ciur.in", ios::in);
ofstream f2("ciur.out", ios::out );
int N;
f >> N;
for (long j=4; j<N+1; j+=2){
ciur[j]=1;
}
for (long i=3; i*i<N+1; i+=2)
if (!ciur[i])
for (long j=i*i; j<N+1; j+= 2*i) {
ciur[j] = 1;
}
for (long i=2; i<N; ++i)
if (!ciur[i])
c++;
f2 << c;
return 0;
}