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

I got AC Here is my solution
Posted by zax 11 Jul 2007 21:41
0.062 sek. 264 KB

const
 n=15001;

var
 a:array [1..n] of longint;
 t,l,m:integer;

procedure Generate_array;
var
 i:integer;
 root:integer;
 k:integer;
 newp:longint;
 prime:boolean;
begin
 a[1]:=2;
 newp:=3;
 i:=2;
 while i<=n do
 begin
  root:=trunc(sqrt(newp));
  k:=1;
  prime:=true;
  while (a[k]<=root) do
  begin
   if newp mod a[k] = 0 then
   begin
    prime:=false;
    break;
   end;
   inc(k);
  end;
  if prime then
  begin
   a[i]:=newp;
   inc(i);
  end;
  inc(newp);
 end;
end;

begin
{$IFNDEF ONLINE_JUDGE}
   assign(input, 'input.txt');
   reset(input);
   assign(output, 'output.txt');
   rewrite(output);
{$ENDIF}
   generate_array;
   readln(l);
   for t:=1 to l do
   begin
    readln(m);
    writeln(a[m]);
   end;
{$IFNDEF ONLINE_JUDGE}
   close(input);
   close(output);
{$ENDIF}
end.

Who has better results?