Cod sursa(job #538284)
| Utilizator | Data | 21 februarie 2011 00:22:59 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#include <stdlib.h>
int count(int n)
{
int k = 0;
int *a = (int*) calloc( n,sizeof(int) );
int p = 2;
while ( p*p <= n )
{
for ( int i=2; i*p <= n; i++ )
a[i*p-1] = 1;
do p++; while ( a[p-1] );
}
for ( int i=2; i<n; i++)
if ( !a[i-1] )
k++;
return k;
}
int main()
{
int n;
FILE *in = fopen("ciur.in", "r");
fscanf(in, "%d", &n);
fclose(in);
FILE *out = fopen("ciur.out", "w");
fprintf( out, "%d", count(n) );
fclose(out);
}
