Cod sursa(job #1686088)
| Utilizator | Data | 12 aprilie 2016 01:47:54 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <fstream>
using namespace std;
bool ciur2[1000000];
long long int tmp2,j,index, n, i, nmax, k=1,l, tmp;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f>>n;
if(n%2==1)
nmax=n/2;
else
nmax=n/2-1;
for(i = 1; i<=nmax; ++i)
{
if(ciur2[i] == 1) continue;
tmp = 2*i+1;
for(j = tmp*tmp; j<=n; j+=tmp)
{
if(j%2==1)
index=j/2;
else
continue;
ciur2[index] = 1;
}
}
for(i=1;i<=nmax;i++)
if(ciur2[i]==0)
k++;
g<<k;
}
