Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Fib::find_fib(int n)
- {
- int v[3];
- int i;
- if (n == 0 || n == 1) return 1;
- v[0] = 1;
- v[1] = 1;
- for (i = 2; i <= n; i++) {
- v[2] = v[0] + v[1];
- v[0] = v[1];
- v[1] = v[2];
- }
- return v[2];
- }
- //instead of using a cache that is n items in size, let's just use three. This saves hella memory with large inputs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement