ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1356. Something Easier

why I got 'ACCESS_VIOLATION'
Posted by visitor 28 Oct 2005 11:25
Here's my program:

program p1356;
var
fb:array[1..600000] of boolean;
pn:array[1..60000] of longint;
np,t,ii,n:longint;

procedure init;
var
i,j:longint;
begin
np:=0;
fillchar(fb,sizeof(fb),true);
fb[1]:=false;
for i:=2 to round(sqrt(600000)) do
if not fb[i] then continue
else begin
inc(np);
pn[np]:=i;
for j:=2 to 600000 div i  do
fb[i*j]:=false;
end;
for i:=round(sqrt(600000)) to 600000 do
if fb[i] then begin
inc(np);
pn[np]:=i;
end;
end;

procedure main;
var
i,j,ij:longint;
begin
if fb[n] then begin
writeln(n);
exit;
end;
if not odd(n) then begin
for i:=1 to np do
if (pn[i]<n)and(fb[n-pn[i]]) then begin
writeln(pn[i],' ',n-pn[i]);
exit;
end;
end
else begin
for i:=1 to np do
if pn[i]>n then break
else if fb[n-pn[i]] then begin
writeln(pn[i],' ',n-pn[i]);
exit;
end
else begin
for j:=1 to np do
if n-pn[i]-pn[j]<0 then break
else if not fb[n-pn[i]-pn[j]] then continue
else begin
writeln(pn[i],' ',pn[j],' ',n-pn[i]-pn[j]);
exit;
end;
end;
end;
end;

begin
init;
if t=0 then halt;
for ii:=1 to t do
begin
main;
end;
end.

Re: why I got WRONG ANSWER :)
Posted by +FAMAS+ 29 Oct 2005 01:09
[code deleted]

Edited by moderator 11.03.2006 17:04
LOL (-)
Posted by Michael Rybak (accepted@ukr.net) 11 Mar 2006 13:29
-