-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfib.cpp
47 lines (32 loc) · 854 Bytes
/
fib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
// void getFib(vector<float> &vFib){
// for(int i=2; i<vFib.size(); ++i)
// vFib[i] = vFib[i-1] + vFib[i-2];
// }
// int main(int argc, char const *argv[]){
// const int n = 50;
// vector<float> vFib(n);
// vFib[0] = 1;
// vFib[1] = 1;
// getFib(vFib);
// printf("Fibonacci %d is %.f\n", n, vFib[n-1]);
// return 0;
// }
template<int N, typename T = int>
struct fibonacci {
static constexpr T value = fibonacci<N-1,T>::value + fibonacci<N-2,T>::value;
};
template<typename T>
struct fibonacci<1,T> {
static constexpr T value = 1;
};
template<typename T>
struct fibonacci<0,T> {
static constexpr T value = 0;
};
int main(int argc, char const *argv[]){
const int n = 100;
cout << "Fibonacci " << n << " is " << fibonacci<n, unsigned long int>::value << endl;
return 0;
}