Cod sursa(job #1686087)
Utilizator | Data | 12 aprilie 2016 01:46:24 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
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,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;
}