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've got ACCCC!!!See my code!!didn't use const.
Posted by a 23 Aug 2003 08:46
0.17sec,86k;
var prost:array[1..16000] of longint;
    i,j,k,x,n:longint;flag:boolean;
procedure look(x:longint);
var i:longint;
begin
  i:=prost[k];
  repeat
    i:=i+2;
    flag:=true;
    for j:=1 to k do begin
      if i mod prost[j]=0 then begin
         flag:=false;
         break;
      end;
      if prost[j]*prost[j]>i then break;{This is very important}
    end;
    if flag then begin
       k:=k+1;
       prost[k]:=i;
    end;
  until k=x;
  writeln(prost[k]);
end;
begin
  prost[1]:=2;
  prost[2]:=3;
  prost[3]:=5;
  k:=3;
  read(n);
  for i:=1 to n do begin
    read(x);
        if x>k then look(x)
           else writeln(prost[x]);
        end;
end.
Hey, it isnt the best solution
Posted by Dont be shy 28 Aug 2003 08:57
without const 0.10sec.
how is you solution??Would you please post it up??
Posted by a 2 Sep 2003 12:27
Re: I've got ACCCC!!!See my code!!didn't use const.
Posted by RASTA 11 Mar 2009 15:40
my solution works in 0.031, but 273 kb
without const...
first of all I calc all the numbers and then only write necessary numbers
Sorry for my English:)

Edited by author 11.03.2009 15:41
Re: I've got ACCCC!!!See my code!!didn't use const.
Posted by amirani 10 Jan 2012 22:39
my time is 0.031 memory 182kb;
mister 'a' in your algo you use i:=i+2; you can check only 6*i-1 or 6*i+1 integers;prime number can't be any other type:))
sorry for my English :)