Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <iostream>
- #include "mpirxx.h"
- template<int N> mpz_class fib(mpz_class& tmp)
- {
- mpz_class t; tmp = fib<N - 1>(t);
- return tmp + t;
- }
- template<> mpz_class fib<1>(mpz_class& tmp) { tmp = 0; return 1; }
- template<> mpz_class fib<2>(mpz_class& tmp) { tmp = 1; return 1; }
- template<int N> mpz_class fib() { return fib<N>(mpz_class()); }
- int main()
- {
- clock_t t_start = clock();
- std::cout << fib<1000>() << std::endl;
- printf("Time: %.3fs\n", (float)(clock() - t_start) / 1000);
- return 0;
- }
- /*
- Output:
- 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080
- 322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875
- Time: 0.001s
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement