View difference between Paste ID: 4LX9h6D4 and DRz3FpEz
SHOW: | | - or go back to the newest paste.
1
#include <ctime>
2
#include <iostream>
3
#include "mpirxx.h"
4
5
template<int N> mpz_class fib(mpz_class& tmp)
6
{
7
    mpz_class t; tmp = fib<N - 1>(t);
8
    return tmp + t;
9
}
10
11
template<> mpz_class fib<1>(mpz_class& tmp) { tmp = 0; return 1; }
12
template<> mpz_class fib<2>(mpz_class& tmp) { tmp = 1; return 1; }
13
template<int N> mpz_class fib() { return fib<N>(mpz_class()); }
14
15
int main()
16
{
17
    clock_t t_start = clock();
18
    std::cout << fib<1000>() << std::endl;
19
    printf("Time: %.3fs\n", (float)(clock() - t_start) / 1000);
20
    return 0;
21
}
22
23
/*
24
Output:
25-
434665576869374564356885276750406258025646605173717804024817290895365554179490518904038798400792551692959225930803
25+
43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080
26-
22634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875
26+
322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875
27
Time: 0.001s
28
*/