Cod sursa(job #209858)

Utilizator 7RaduRadu Antohi 7Radu Data 25 septembrie 2008 09:15:13
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.66 kb
program Ciur;
var
   a : array[1..200000] of char ;
   n,i,j,k:longint;
   fl:text;
begin
   assign(fl,'ciur.in');
   reset(fl);
   readln(fl,n);
   close(fl);

   for i := 1 to n do
      a[i] := '1';

   i := 3;
   while i <= n div 2 do
      begin
          j := 3;
          while j <= n div i do
             begin
                a[i*j] := '0';
                j := j+2;
             end;
          i := i+2;
      end;

   assign(fl,'ciur.out');
   rewrite(fl);
   write(fl,'2 ');
   i := 3;
   while i <= n do
      begin
         if a[i] = '1' then
            write(fl,i,' ');
         i := i+2;
      end;
  close(fl);

end.