Cod sursa(job #630804)

Utilizator yippeeErja Eduard yippee Data 6 noiembrie 2011 16:36:12
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n;
    FILE *f = fopen("ciur.in","r");
    fscanf(f,"%d", &n);
    int a[sizeof(n)];

    a[0] = 2;
    int k = 1,sw,x = 1;
    while(x<=n)
    {
      x += 2;
      sw = 1;
      for(int i=0;i<k;i++)
        if(x % a[i] == 0)
          {
              sw = 0;
              break;
          }

      if(sw)
        a[k++] = x;
    }

    f = fopen("ciur.out","w");
    fprintf(f,"%d", k-1);

    return 0;
}