Cod sursa(job #1387188)
Utilizator | Data | 13 martie 2015 19:56:07 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include<fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
long long n;
bool v[2000010];
long long s;
void citire()
{
fin>>n;
}
void fct()
{
long long x;
for(long long a1=2;a1<=n;a1++)
{
if(v[a1]==0)
{
s++;
x=a1*a1;
while(x<=n)
{
v[x]=1;
x+=a1;
}
}
}
}
int main()
{
citire();
fct();
fout<<s;
}