PNUMBER - Tìm số nguyên tố

Tác giả: ll931110

Ngôn ngữ: Pascal

Program PNUMBER;
        Const
                input  = '';
                output = '';
        Var
                a,b: longint;
                x: array[1..200000] of integer;

Procedure init;
          Var
                f: text;
          Begin
                Assign(f, input);
                        Reset(f);
                        Readln(f, a, b);
                Close(f);
                Fillchar(x, sizeof(x), 0);
                x[1]:= 1;
          End;

Procedure prime;
          Var
                f: text;
                i,k: longint;
          Begin
                For i:= 2 to trunc(sqrt(b)) do
                        If x[i] = 0 then
                                Begin
                                      k:= 2;
                                      While k * i <= b do
                                            Begin
                                                inc(x[k * i]);
                                                inc(k);
                                            End;
                                End;

                Assign(f, output);
                        Rewrite(f);
                        For i:= a to b do if x[i] = 0 then writeln(f, i);
                Close(f);
          End;

Begin
        init;
        prime;
End.

Download