Cod sursa(job #1998996)

Utilizator FlorinHajaFlorin Gabriel Haja FlorinHaja Data 9 iulie 2017 21:45:27
Problema Nunta Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.23 kb

Program nunta;

var i, j, n : integer;
    f1, f2, f3, t , m1: longint;
    a1, a2, a3 : array [0..1005] of integer;


begin
    assign(input,'nunta.in');
    reset(input);
    assign(output,'nunta.out');
    rewrite(output);

    read(n);
    f1 := 1;
    f2 := 2;
    if (n < 3) then
    begin
        writeln(n);
        close(input);
        close(output);
        exit;
    end;
    a1[0] := 1;
    a2[0] := 1;
    a1[1] := 1;
    a2[1] := 2;

    for i := 3 to n do
    begin
       { f3 := f1+f2;
        f1 := f2;
        f2 := f3;}
        t := 0;
        if (a1[0] > a2[0])
        then m1 := a1[0]
        else m1 := a2[0];
        for j := 1 to m1 do
        begin
            t := t+a1[j]+a2[j];
            a3[j] := t mod 10;
            t := t div 10;
        end;
        a3[0] := m1;
        while t > 0 do
        begin
            inc(a3[0]);
            a3[j] := t mod 10;
            t := t div 10;
        end;
        for j := 0 to a2[0] do
            a1[j] := a2[j];
        for j := 0 to a3[0] do
            a2[j] := a3[j];
    end;
    i := a3[0];
    while (i > 0) do
    begin
        write(a3[i]);
        dec(i);
    end;
    close(input);
    close(output);
end.