We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Despite having recurrence relation, I have no doubt that this doesn't belong to DP category.
You can use C++'s external library: (gmpxx.h) Note that "Online Judges" don't know about the external library, and if you submit the below code, you are definitely going to fail.
Efficiency and speed are significantly faster than those from Java and Python's built-in libraries. It's worth to learn it because the problem only requires you to implement super simple recurrence relation.
include
include
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
mpz_class t1, t2, ret;
int nth;
cin >> t1 >> t2 >> nth;
for(int i = 2; i < nth; ++i) {
ret = t1 + t2 * t2;
t1 = t2; t2 = ret;
}
cout << ret << endl;
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →
Despite having recurrence relation, I have no doubt that this doesn't belong to DP category.
You can use C++'s external library: (gmpxx.h) Note that "Online Judges" don't know about the external library, and if you submit the below code, you are definitely going to fail.
Efficiency and speed are significantly faster than those from Java and Python's built-in libraries. It's worth to learn it because the problem only requires you to implement super simple recurrence relation.
include
include
using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
}