#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <givaro/givinteger.h>
#define GMPFIBTABLESIZE 93
#define GMPCNSTUINT(C) ((uint64_t) C##u)
const uint64_t givfibtable[GMPFIBTABLESIZE+2] {
GMPCNSTUINT (0x1),
GMPCNSTUINT (0x0),
GMPCNSTUINT (0x1),
GMPCNSTUINT (0x1),
GMPCNSTUINT (0x2),
GMPCNSTUINT (0x3),
GMPCNSTUINT (0x5),
GMPCNSTUINT (0x8),
GMPCNSTUINT (0xd),
GMPCNSTUINT (0x15),
GMPCNSTUINT (0x22),
GMPCNSTUINT (0x37),
GMPCNSTUINT (0x59),
GMPCNSTUINT (0x90),
GMPCNSTUINT (0xe9),
GMPCNSTUINT (0x179),
GMPCNSTUINT (0x262),
GMPCNSTUINT (0x3db),
GMPCNSTUINT (0x63d),
GMPCNSTUINT (0xa18),
GMPCNSTUINT (0x1055),
GMPCNSTUINT (0x1a6d),
GMPCNSTUINT (0x2ac2),
GMPCNSTUINT (0x452f),
GMPCNSTUINT (0x6ff1),
GMPCNSTUINT (0xb520),
GMPCNSTUINT (0x12511),
GMPCNSTUINT (0x1da31),
GMPCNSTUINT (0x2ff42),
GMPCNSTUINT (0x4d973),
GMPCNSTUINT (0x7d8b5),
GMPCNSTUINT (0xcb228),
GMPCNSTUINT (0x148add),
GMPCNSTUINT (0x213d05),
GMPCNSTUINT (0x35c7e2),
GMPCNSTUINT (0x5704e7),
GMPCNSTUINT (0x8cccc9),
GMPCNSTUINT (0xe3d1b0),
GMPCNSTUINT (0x1709e79),
GMPCNSTUINT (0x2547029),
GMPCNSTUINT (0x3c50ea2),
GMPCNSTUINT (0x6197ecb),
GMPCNSTUINT (0x9de8d6d),
GMPCNSTUINT (0xff80c38),
GMPCNSTUINT (0x19d699a5),
GMPCNSTUINT (0x29cea5dd),
GMPCNSTUINT (0x43a53f82),
GMPCNSTUINT (0x6d73e55f),
GMPCNSTUINT (0xb11924e1),
GMPCNSTUINT (0x11e8d0a40),
GMPCNSTUINT (0x1cfa62f21),
GMPCNSTUINT (0x2ee333961),
GMPCNSTUINT (0x4bdd96882),
GMPCNSTUINT (0x7ac0ca1e3),
GMPCNSTUINT (0xc69e60a65),
GMPCNSTUINT (0x1415f2ac48),
GMPCNSTUINT (0x207fd8b6ad),
GMPCNSTUINT (0x3495cb62f5),
GMPCNSTUINT (0x5515a419a2),
GMPCNSTUINT (0x89ab6f7c97),
GMPCNSTUINT (0xdec1139639),
GMPCNSTUINT (0x1686c8312d0),
GMPCNSTUINT (0x2472d96a909),
GMPCNSTUINT (0x3af9a19bbd9),
GMPCNSTUINT (0x5f6c7b064e2),
GMPCNSTUINT (0x9a661ca20bb),
GMPCNSTUINT (0xf9d297a859d),
GMPCNSTUINT (0x19438b44a658),
GMPCNSTUINT (0x28e0b4bf2bf5),
GMPCNSTUINT (0x42244003d24d),
GMPCNSTUINT (0x6b04f4c2fe42),
GMPCNSTUINT (0xad2934c6d08f),
GMPCNSTUINT (0x1182e2989ced1),
GMPCNSTUINT (0x1c5575e509f60),
GMPCNSTUINT (0x2dd8587da6e31),
GMPCNSTUINT (0x4a2dce62b0d91),
GMPCNSTUINT (0x780626e057bc2),
GMPCNSTUINT (0xc233f54308953),
GMPCNSTUINT (0x13a3a1c2360515),
GMPCNSTUINT (0x1fc6e116668e68),
GMPCNSTUINT (0x336a82d89c937d),
GMPCNSTUINT (0x533163ef0321e5),
GMPCNSTUINT (0x869be6c79fb562),
GMPCNSTUINT (0xd9cd4ab6a2d747),
GMPCNSTUINT (0x16069317e428ca9),
GMPCNSTUINT (0x23a367c34e563f0),
GMPCNSTUINT (0x39a9fadb327f099),
GMPCNSTUINT (0x5d4d629e80d5489),
GMPCNSTUINT (0x96f75d79b354522),
GMPCNSTUINT (0xf444c01834299ab),
GMPCNSTUINT (0x18b3c1d91e77decd),
GMPCNSTUINT (0x27f80ddaa1ba7878),
GMPCNSTUINT (0x40abcfb3c0325745),
GMPCNSTUINT (0x68a3dd8e61eccfbd),
GMPCNSTUINT (0xa94fad42221f2702),
};
Integer& Fibonacci(Integer& r, Integer& t,
const uint64_t n) {
if (n <= 93) {
uint64_t k(n);
r=givfibtable[k];
return t=givfibtable[++k];
}
uint64_t k(n); ++k; k >>=1 ;
Fibonacci(t,r,k);
if (n & 1u) {
Integer b(r);
r <<= 1;
r -= t;
r *= t;
t <<= 1;
t += b;
t *= b;
t -= r;
} else {
Integer b(t);
t <<= 1;
t += r;
t *= r;
r <<= 1;
r *= b;
r += t;
}
return t;
}
Integer& Fibonacci(Integer& t, const uint64_t n) {
Integer a;
if (n & 1u) {
uint64_t k(n); ++k; k >>=1 ;
Fibonacci(t,a,k);
Integer b(t);
t <<= 1;
t += a;
t *= b;
return ( (k & 1u)? ++t : --t );
} else {
Fibonacci(t,a, n>>1 );
t <<= 1;
t += a;
return t *= a;
}
}
}
int main (int argc, char * * argv) {
uint64_t n = argc > 1 ? (uint64_t)atoi(argv[1]) : 42u;
Givaro::Fibonacci(t,n);
std::cout << t << std::endl;
std::clog << tim << std::endl;
return 0;
}
This is the Integer class.
Definition: gmp++_int.h:160
static giv_all_inlined Integer & sub(Integer &res, const Integer &n1, const Integer &n2)
Substraction res=n1-n2.
Definition: gmp++_int_sub.C:58
Timer.
Definition: givtimer.h:129
void start()
Start timer.
Definition: givtimer.C:164
void stop()
Stop timer.
Definition: givtimer.C:172
Namespace in which the whole Givaro library resides.
Definition: all_field.C:23