• + 0 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);

    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; 
    

    }