Cod sursa(job #1569401)
| Utilizator | Data | 15 ianuarie 2016 15:04:34 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("ciur.in");
ofstream g("ciur.out");
int n, i, t, j, gasit = 1, k, nr = 0;
f >> n;
for(i=2;i<=n;i++)
{
t=i;
gasit = 1;
if((t%2==0)&&(t!=2)) gasit = 0;
else
{
for(k=3;k<=t/2;k+=2)
{
if(t%k==0) gasit = 0;
}
}
if (gasit==1) nr++;
}
g << nr;
f.close();
g.close();
return 0;
}
