Cod sursa(job #1424715)
Utilizator | Data | 25 aprilie 2015 13:30:48 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n,i,j,nr=0;
char v[2001000];
ifstream f1("ciur.in");
ofstream f2("ciur.out");
f1 >> n;
for(i=2;i<=n;++i)
{
if (v[i]==0)
{
nr++;
for(j=i+i;j<=n;j+=i)
{
v[j]=1;
}
}
}
f2 << nr;
f2.close();
return 0;
}