Cod sursa(job #371755)
| Utilizator | Data | 6 decembrie 2009 19:41:02 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.74 kb |
#include<stdio.h>
#include<stdlib.h>
int main()
{
freopen("ciur.in","r",stdin);
freopen("ciur.out","w",stdout);
int n;
char ciur[2000001];
scanf("%d", &n);
fclose(stdin);
int i=2;
for(i=2; i<=n; i++)
{
ciur[i]='1';
}
int j=2;
while(j<=n)
{
if(ciur[j]=='1')
{
int i=j+j;
for(i=j+j; i<=n; i+=j)
ciur[i]='0';
}
j++;
}
int sol=0,e=2;
for(e=2; e<=n; e++)
{
if(ciur[e]=='1')
sol++;
}
printf("%d",sol);
fclose(stdout);
return 0;
}
