function tri(n: integer): longint; begin case n of 0,1: tri := 0; 2: tri := 1 else tri := tri(n - 3) + tri(n - 2)+tri(n-1); end; end;
var a: array of integer; i: longint;
begin readln(N); setlength(a, N); for i := 0 to N-1 do Write(tri(i) + ' '); for i := 0 to N-1 do a[i] := tri(i); writeln(''); for i := 0 to N-1 do if a[i] mod 3 = 0 then write(a[i] + ' '); end.
Answers & Comments
Verified answer
// PascalABC.NET 3.2, сборка 1439 от 09.05.2017var
N: integer;
function tri(n: integer): longint;
begin
case n of
0,1: tri := 0;
2: tri := 1
else
tri := tri(n - 3) + tri(n - 2)+tri(n-1);
end;
end;
var
a: array of integer;
i: longint;
begin
readln(N);
setlength(a, N);
for i := 0 to N-1 do
Write(tri(i) + ' ');
for i := 0 to N-1 do
a[i] := tri(i);
writeln('');
for i := 0 to N-1 do
if a[i] mod 3 = 0 then
write(a[i] + ' ');
end.