Cod sursa(job #1922678)
| Utilizator | Data | 10 martie 2017 18:24:04 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include<fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int main()
{
int n,div=2,nr=0;
f>>n;
bool a[n],ok=false;
for(int i=0;i<n;i++)
a[i]=0;
a[0]=1;
a[1]=1;
while(div<=n && ok==false)
{
ok=true;
for(int i=div*2;i<n;i+=div)
a[i]=1;
for(int i=div+1;i<n,ok==true;i++)
if(a[i]==0)
{
ok=false;
div=i;
}
}
for(int i=0;i<n;i++)
if(!a[i])
nr++;
g<<nr;
}
