Cod sursa(job #1316175)
| Utilizator | Data | 13 ianuarie 2015 16:43:30 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 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) {prim[p]=1; k++;}
int c=2;
int mul=p*c;
while(mul<=n)
{
prim[mul]=-1;
c++;
mul=p*c;
}
}
}
int main()
{
f>>n;
eratostene(n);
g<<k;
return 0;
}
