Cod sursa(job #1684730)
| Utilizator | Data | 11 aprilie 2016 11:40:08 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 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[2*i+1]==0)
k++;
g<<k;
}
