|
|
вернуться в форумI've got ACCCC!!!See my code!!didn't use const. Послано a 23 авг 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 without const 0.10sec. how is you solution??Would you please post it up?? Послано a 2 сен 2003 12:27 Re: I've got ACCCC!!!See my code!!didn't use const. Послано RASTA 11 мар 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. 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 :) |
|
|