Cod sursa(job #630816)
Utilizator | Data | 6 noiembrie 2011 16:48:37 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
long n;
FILE *f = fopen("ciur.in","r");
fscanf(f,"%f", &n);
long a[sizeof(n)];
a[0] = 2;
int k = 1;
long x = 3;
while(x<=n)
{
int sw = 1;
for(int i=0;i<k && sw;i++)
if(x % a[i] == 0)
sw = 0;
if(sw)
a[k++] = x;
x += 2 ;
}
f = fopen("ciur.out","w");
fprintf(f,"%f", k);
return 0;
}