Cod sursa(job #1316623)
Utilizator | Data | 13 ianuarie 2015 22:50:27 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include<fstream>
#define maxn 2000001
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
char prim[maxn];
int n;
int i,k=0;
void eratostene(int n)
{
for(int p=2;p<n;p++)
{
if(prim[p]==0)
{
k++;
for(i=p;i<=n;i=i+p)
prim[i]=1;
}
}
}
int main()
{
f>>n;
eratostene(n);
g<<k;
return 0;
}