Cod sursa(job #1683650)
| Utilizator | Data | 10 aprilie 2016 15:37:06 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
using namespace std;
int n,i,tmp,j,nmax,k;
bool ciur2[1000001];
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
f>>n;
nmax=n/2;
for(int i = 1; i<=nmax; ++i)
{
if(ciur2[i] == 1) continue;
int tmp = 2*i+1;//
for(int j = tmp*tmp; j<=n; j+=tmp)
{
int tmp2 = j/2;
ciur2[tmp2] = 1;
}
}
for(int i=1;i<=nmax;i++)
if(ciur2[i]==0)
k++;
g<<k;
}
