#include <iostream>#include <vector>#include <gmp.h>class Fibonacci {private: std::vector<mpz_t> lookupTable;public: class numberToLarge { }; Fibonacci ( ) { mpz_t zero, one; mpz_init_set_ui ( zero, (unsigned long int)0 ); mpz_init_set_ui ( one, (unsigned long int)1 ); /* Insert zero and one into the lookuptable. */ lookupTable.push_back ( zero ); lookupTable.push_back ( one ); } /* Wrapper function to use unsigned long int as argument. */ void at ( mpz_t answer, unsigned long int n ) { mpz_t temp; mpz_init_set_ui ( temp, n ); at ( answer, temp ); } /* The real fibonacci calculator. */ void at ( mpz_t answer, mpz_t n ) { /* If we have 1 or 0, just return that. */ if ( mpz_cmp_ui ( n, 1 ) <= 0 ) { mpz_set ( answer, n ); return; } /* Check if the number already has been calculated. */ if ( mpz_cmp_ui ( n, (unsigned long int)lookupTable.size ( ) ) < 0 ) { if ( mpz_fits_sint_p ( n ) == 0 ) throw Fibonacci::numberToLarge ( ); mpz_set ( answer, lookupTable.at ( (int)mpz_get_si ( n ) ) ); return; } /* Face the truth, we have to calculate it. :| */ mpz_t n1, n2, n3; mpz_init_set ( n1, n ); mpz_init_set ( n2, n ); mpz_init ( n3 ); mpz_sub_ui ( n1, n1, (unsigned long int)1 ); mpz_sub_ui ( n2, n2, (unsigned long int)2 ); at ( n1, n1 ); at ( n2, n2 ); mpz_add ( answer, n1, n2 ); /** * Detta behver jag hjlp med, jag vill peta in vrdet i min vector s * jag kan ta fram detta senare s det gr snabbare att plocka fram de * strre talen... n > 20 * * Felet som blir: * fib.cpp:63: error: no matching function for call to std::vector<__mpz_struct [1], \ * std::allocator<__mpz_struct [1]> >::push_back(__mpz_struct*&) * usr/lib/gcc/i686-pc-linux-gnu/4.2.3/../../../../include/c++/4.2.3/bits/stl_vector.h:597: \ * note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp \ * = __mpz_struct [1], _Alloc = std::allocator<__mpz_struct [1]>] */ lookupTable.push_back ( answer ); } ~Fibonacci ( void ) { std::vector<mpz_t>::iterator it; for ( it = lookupTable.begin ( ); it != lookupTable.end ( ); it++ ) mpz_clear ( *it ); }};int main ( int argc, char ** argv ) { mpz_t answer; mpz_init ( answer ); unsigned long int calc; Fibonacci fn; while ( std::cin >> calc ) { fn.at ( answer, calc ); std::cout << "The number at " << calc << " of the Fibonacci sequenze " << "is "; mpz_out_str ( NULL, 10, answer ); std::cout << "." << std::endl; }}