Re: Who can help me? I have WA8...
Послано
Rustam 13 ноя 2008 17:10
i also have WA#8. here is my code:
program z1356;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
n,k,c,i,j,t,p:longint;
const mas :array [1..5133] of longint = (
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,
73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,
179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,
283,//etc :) last number 49999///
);
procedure init;
begin
{$IFNDEF ONLINE_JUDGE}
assign(input,'input.txt');
reset(Input);
assign(output,'output.txt');
rewrite(output);
{$ENDIF}
end;
procedure print;
begin
{$IFNDEF ONLINE_JUDGE}
close(input);
close(output);
{$ENDIF}
halt(0);
end;
function simple(x:longint):boolean;
var i:longint;
begin
result:=false;
if x=1 then exit;
if x=2 then begin
result:=true;
exit;
end;
for i:=2 to trunc(sqrt(x)) do
if x mod i=0 then exit;
result:=true;
end;
function canbe(x,k,st:longint):boolean;
var i:longint;
begin
if (x=0) then result:=true else
if (k=3) then begin
if simple(x) then begin
result:=true;
write(x,' ');
end
else result:=false;
end else
begin
canbe:=false;
while mas[st]>x do
dec(st);
for i:=st downto 1 do
begin
result:=canbe(x-mas[i],k+1,st);
if result then
begin
write(mas[i],' ');
exit;
end;
end;
end;
end;
procedure couldbe(t:longint);
var i,k:longint;
begin
k:=5133;
while mas[k]>t do dec(k);
if mas[k]=t then write(mas[k]) else begin
for i:=k downto 1 do
if simple(t-mas[i]) then begin
write(mas[i], ' ',t-mas[i]);
exit;
end;
end;
end;
begin
init;
read(n);
for i:=1 to n do begin
read(t);
if odd(t) then
canbe(t,1,5133) else
couldbe(t);
writeln;
end;
print;
end.