3. 1 .. N内的所有合数

3. 1 .. N内的所有合数
program ex_3;
var
     a : array [2..10000] of boolean;
     n, i, j, x : integer;
begin
     readln(n);
     for i := 2 to n do
         a[i] := true;
     x := 1;
     repeat
           x := x+1;
           if a[x] then
           begin
                i := x;
                while i < n do
                begin
                     i := i+x;
                     a[i] := false;
                end;
           end;
     until x*x > n;
     j := 0;
     for i := 2 to n do
         if a[i] = false then
         begin
              j := j+1;
              if j mod 10 <> 0 then
                  write(i, ' ')
              else
                  writeln(i);
      end;
      readln;
end.
posted @ 2010-02-25 16:10  SmartIOI  阅读(128)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License