Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll Fib(int n) {
- if (n == 0 || n == 1) return 1ll;
- ll prev = 1ll;
- ll current = 1ll;
- for (int i = 0; i < n - 1; ++i) {
- ll next = prev + current;
- prev = current;
- current = next;
- }
- return current;
- }
- int main() {
- int n = 0;
- std::cin >> n;
- std::cout << Fib(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement