ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1133. Fibonacci Sequence

what's wrong with my program?
Posted by Sum 1 5 Feb 2003 20:11
var
   i, j, n, p, q: longint;
   Fi, Fj, Fi1, Fn: extended;
   F: array [1..2, 1..2] of extended;

begin
     readln(i, Fi, j, Fj, n);

     F[1, 1] := 1; F[1, 2] := 0;
     F[2, 1] := 0; F[2, 2] := 1;
     if i < j then begin
        q := 2;
        for p := i + 2 to j do begin
            q := 3 - q;
            F[q, 1] := F[q, 1] + F[3 - q, 1];
            F[q, 2] := F[q, 2] + F[3 - q, 2];
        end;
     end
     else begin
        q := 1;
        for p := i - 1 downto j do begin
            q := 3 - q;
            F[q, 1] := F[q, 1] - F[3 - q, 1];
            F[q, 2] := F[q, 2] - F[3 - q, 2];
        end;
     end;
     Fi1 := (Fj - Fi * F[q, 1]) / F[q, 2];

     F[1, 1] := 1; F[1, 2] := 0;
     F[2, 1] := 0; F[2, 2] := 1;
     if i < n then begin
        q := 2;
        for p := i + 2 to n do begin
            q := 3 - q;
            F[q, 1] := F[q, 1] + F[3 - q, 1];
            F[q, 2] := F[q, 2] + F[3 - q, 2];
        end;
     end
     else begin
        q := 1;
        for p := i - 1 downto n do begin
            q := 3 - q;
            F[q, 1] := F[q, 1] - F[3 - q, 1];
            F[q, 2] := F[q, 2] - F[3 - q, 2];
        end;
     end;
     Fn := Fi * F[q, 1] + Fi1 * F[q, 2];

     if Fn = 0 then writeln(0) else writeln(Fn: 0: 0);
end.
If you want I give you my AC program
Posted by Yuriy Frolov (ufrolov@ukr.net) 6 Feb 2003 00:59
I've got AC!!!
Posted by Sum 1 3 Mar 2003 15:09