Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,8 +1,17 @@
|
|||
function fib(n: integer): integer;
|
||||
begin
|
||||
if (n = 0) or (n = 1)
|
||||
then
|
||||
fib := n
|
||||
else
|
||||
fib := fib(n-1) + fib(n-2)
|
||||
end;
|
||||
function fib(n: integer):longInt;
|
||||
const
|
||||
Sqrt5 = sqrt(5.0);
|
||||
C1 = ln((Sqrt5+1.0)*0.5);//ln( 1.618..)
|
||||
//C2 = ln((1.0-Sqrt5)*0.5);//ln(-0.618 )) tsetsetse
|
||||
C2 = ln((Sqrt5-1.0)*0.5);//ln(+0.618 ))
|
||||
begin
|
||||
IF n>0 then
|
||||
begin
|
||||
IF odd(n) then
|
||||
fib := round((exp(C1*n) + exp(C2*n) )/Sqrt5)
|
||||
else
|
||||
fib := round((exp(C1*n) - exp(C2*n) )/Sqrt5)
|
||||
end
|
||||
else
|
||||
Fibdirekt := 0
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,8 @@
|
|||
function fib(n: integer): integer;
|
||||
var
|
||||
f0, f1, tmpf0, k: integer;
|
||||
begin
|
||||
f1 := n;
|
||||
IF f1 >1 then
|
||||
begin
|
||||
k := f1-1;
|
||||
f0 := 0;
|
||||
f1 := 1;
|
||||
repeat
|
||||
tmpf0 := f0;
|
||||
f0 := f1;
|
||||
f1 := f1+tmpf0;
|
||||
dec(k);
|
||||
until k = 0;
|
||||
end
|
||||
else
|
||||
IF f1 < 0 then
|
||||
f1 := 0;
|
||||
fib := f1;
|
||||
end;
|
||||
begin
|
||||
if (n = 0) or (n = 1)
|
||||
then
|
||||
fib := n
|
||||
else
|
||||
fib := fib(n-1) + fib(n-2)
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,22 @@
|
|||
function FiboMax(n: integer):Extended; //maXbox
|
||||
function fib(n: integer): integer;
|
||||
var
|
||||
f0, f1, tmpf0, k: integer;
|
||||
begin
|
||||
result:= (pow((1+SQRT5)/2,n)-pow((1-SQRT5)/2,n))/SQRT5
|
||||
f1 := n;
|
||||
IF f1 >1 then
|
||||
begin
|
||||
k := f1-1;
|
||||
f0 := 0;
|
||||
f1 := 1;
|
||||
repeat
|
||||
tmpf0 := f0;
|
||||
f0 := f1;
|
||||
f1 := f1+tmpf0;
|
||||
dec(k);
|
||||
until k = 0;
|
||||
end
|
||||
else
|
||||
IF f1 < 0 then
|
||||
f1 := 0;
|
||||
fib := f1;
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,4 @@
|
|||
function Fibo_BigInt(n: integer): string; //maXbox
|
||||
var tbig1, tbig2, tbig3: TInteger;
|
||||
begin
|
||||
result:= '0'
|
||||
tbig1:= TInteger.create(1); //temp
|
||||
tbig2:= TInteger.create(0); //result (a)
|
||||
tbig3:= Tinteger.create(1); //b
|
||||
for it:= 1 to n do begin
|
||||
tbig1.assign(tbig2)
|
||||
tbig2.assign(tbig3);
|
||||
tbig1.add(tbig3);
|
||||
tbig3.assign(tbig1);
|
||||
end;
|
||||
result:= tbig2.toString(false)
|
||||
tbig3.free;
|
||||
tbig2.free;
|
||||
tbig1.free;
|
||||
end;
|
||||
function FiboMax(n: integer):Extended; //maXbox
|
||||
begin
|
||||
result:= (pow((1+SQRT5)/2,n)-pow((1-SQRT5)/2,n))/SQRT5
|
||||
end;
|
||||
|
|
|
|||
|
|
@ -1,62 +1,18 @@
|
|||
program Fibonacci_console;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
function Fibonacci( n : word) : uint64;
|
||||
{
|
||||
Starts with the pair F[0],F[1]. At each iteration, uses the doubling formulae
|
||||
to pass from F[k],F[k+1] to F[2k],F[2k+1]. If the current bit of n (starting
|
||||
from the high end) is 1, there is a further step to F[2k+1],F[2k+2].
|
||||
}
|
||||
var
|
||||
marker, half_n : word;
|
||||
f, g : uint64; // pair of consecutive Fibonacci numbers
|
||||
t, u : uint64; // -----"-----
|
||||
begin
|
||||
// The values of F[0], F[1], F[2] are assumed to be known
|
||||
case n of
|
||||
0 : result := 0;
|
||||
1, 2 : result := 1;
|
||||
else begin
|
||||
half_n := n shr 1;
|
||||
marker := 1;
|
||||
while marker <= half_n do marker := marker shl 1;
|
||||
|
||||
// First time: current bit is 1 by construction,
|
||||
// so go straight from F[0],F[1] to F[1],F[2].
|
||||
f := 1; // = F[1]
|
||||
g := 1; // = F[2]
|
||||
marker := marker shr 1;
|
||||
|
||||
while marker > 1 do begin
|
||||
t := f*(2*g - f);
|
||||
u := f*f + g*g;
|
||||
if (n and marker = 0) then begin
|
||||
f := t;
|
||||
g := u;
|
||||
end
|
||||
else begin
|
||||
f := u;
|
||||
g := t + u;
|
||||
end;
|
||||
marker := marker shr 1;
|
||||
end;
|
||||
|
||||
// Last time: we need only one of the pair.
|
||||
if (n and marker = 0) then
|
||||
result := f*(2*g - f)
|
||||
else
|
||||
result := f*f + g*g;
|
||||
end; // end else (i.e. n > 2)
|
||||
end; // end case
|
||||
end;
|
||||
|
||||
// Main program
|
||||
var
|
||||
n : word;
|
||||
begin
|
||||
for n := 0 to 93 do
|
||||
WriteLn( SysUtils.Format( 'F[%2u] = %20u', [n, Fibonacci(n)]));
|
||||
end.
|
||||
function Fibo_BigInt(n: integer): string; //maXbox
|
||||
var tbig1, tbig2, tbig3: TInteger;
|
||||
begin
|
||||
result:= '0'
|
||||
tbig1:= TInteger.create(1); //temp
|
||||
tbig2:= TInteger.create(0); //result (a)
|
||||
tbig3:= Tinteger.create(1); //b
|
||||
for it:= 1 to n do begin
|
||||
tbig1.assign(tbig2)
|
||||
tbig2.assign(tbig3);
|
||||
tbig1.add(tbig3);
|
||||
tbig3.assign(tbig1);
|
||||
end;
|
||||
result:= tbig2.toString(false)
|
||||
tbig3.free;
|
||||
tbig2.free;
|
||||
tbig1.free;
|
||||
end;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue