ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1086. Cryptography

Why my program work so long???
Posted by S7 18 Jul 2003 01:45
This is my solve. Judge write Time Limit Ex.. But on my PC program very fast.. Why??/?

{ @JUDGE_ID: 22797EM 1086 Pascal }
program Cryptography_1086;
const
     max=15000;
type
    int=1..max;
    mas_find=array [int] of longint;
var
   limit:integer;
   k,i,j,kolvo,n:int;
   simple:boolean;
   candidat:longint;
   Find:mas_find;
BEGIN
     readln(k);

     for i:=1 to k do
     begin
          readln(n);

          if n=1 then
          begin
               writeln(2);
               continue;
          end;

          candidat:=3;
          find[1]:=2;
          kolvo:=1;

          while kolvo<n do
          begin
               limit:=trunc(sqrt(candidat));
               simple:=true;
               for j:=1 to kolvo do
               begin
                    if j=1 then
                       continue;
                    if Find[j]>limit then
                       break;
                    if candidat mod find[j]=0 then
                    begin
                         simple:=false;
                         break;
                    end;
               end;

               if simple then
               begin
                    inc(kolvo);
                    find[kolvo]:=candidat;
               end;

               inc(candidat,2);
          end;

          writeln(Find[kolvo]);
     end;
END.
Re: Why my program work so long???
Posted by GodZilla 18 Jul 2003 02:27
Use Eratosfen Grid