Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- using namespace std;
- unordered_map<long long, long long> Fib;
- long long fib(long long n)
- {
- if (n < 2) return 1;
- if (Fib.find(n) != Fib.end()) return Fib[n];
- Fib[n] = (fib((n + 1) / 2) * fib(n / 2) + fib((n - 1) / 2) * fib((n - 2) / 2)) % 1000000007;
- return Fib[n];
- }
- int main()
- {
- long long N;
- cin >> N;
- cout << fib(N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement