Mai intai trebuie sa te autentifici.
Cod sursa(job #288399)
| Utilizator | Data | 25 martie 2009 19:24:04 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include<fstream.h>
unsigned long i=3,n,ciur=1;
unsigned long CHESTIE(unsigned long);
unsigned long PRIM(unsigned long);
main()
{
ifstream In("ciur.in");
ofstream Out("ciur.out");
In>>n;
In.close();
for(;i<=n;i+=2)
{
if(CHESTIE(i))
if(PRIM(i)) ciur++;
}
Out<<ciur<<'\n';
Out.close();
return 0;
}
unsigned long PRIM(unsigned long x)
{
short ok=1;
for(unsigned long d=3;d<=x/2;d+=2) if(x%d==0) {ok=0;break;}
return ok;
}
unsigned long CHESTIE(unsigned long x)
{
short ok=1;
if(x%3==0 || x%5==0 || x%7==0) ok=0;
return ok;
}
