Cod sursa(job #115216)

Utilizator vanila_CPPIonescu Victor Cristian vanila_CPP Data 16 decembrie 2007 11:41:55
Problema Nunta Scor 100
Compilator fpc Status done
Runda preONI 2008, Runda 2, Clasa a 9-a Marime 2.25 kb
program nunta;
type vector=array[0..20001] of integer;
var f,g:text;
        n:longint;
        v:array[0..1] of vector;


procedure iofile;
begin
        assign(f,'nunta.in');reset(f);
        assign(g,'nunta.out');rewrite(g);
        readln(f,n);
        close(f);
end;




procedure add(var a,b:vector);
var t,x,i:longint;
begin
        i:=1;
        t:=0;
        while (i<=a[0])and(i<=b[0]) do
                begin
                        x:=a[i]+b[i]+t;
                        a[i]:=x mod 10;
                        t:=x div 10;
                        inc(i);
                end;
        if i<=a[0] then
                while i<=a[0] do
                        begin
                                x:=a[i]+t;
                                a[i]:=x mod 10;
                                t:=x div 10;
                                inc(i);
                        end else
                while i<=b[0] do
                        begin
                                x:=b[i]+t;
                                a[i]:=x mod 10;
                                t:=x div 10;
                                inc(i);
                        end;
        a[0]:=i-1;
        if t<>0 then
                begin
                        inc(a[0]);
                        a[a[0]]:=t;
                end;
end;




procedure fibo;
var i:longint;
        stare:byte;
begin
        if (n=1)or(n=2) then
                begin
                        writeln(g,n);
                        close(g);
                end else
                begin
                        v[0][0]:=1;
                        v[0][1]:=1;
                        v[1][0]:=1;
                        v[1][1]:=2;
                        stare:=0;
                        for i:=3 to n do
                                begin
                                        add(v[stare],v[1-stare]);
                                        stare:=1-stare;
                                end;
                        for i:=v[1-stare][0] downto 1 do
                                write(g,v[1-stare][i]);
                        writeln(g);
                        close(g);
                end;
end;


begin
        iofile;
        fibo;
end.