Submission

Status:
PPPxxxxxxx

Score: 30

User: Jibhong

Problemset: Medulla

Language: cpp

Time: 0.007 second

Submitted On: 2024-12-13 19:59:15

#include <bits/stdc++.h>
using namespace std;

#define ll long long

vector <ll> mem (20020,-1);

ll last=3;

ll func(ll x){
    if(mem[x]!=-1)return mem[x];
    for(;last<=x;++last){
        mem[last] = ((func(last-3)*func(last-3)*func(last-3))%20011+(func(last-2)*func(last-1))%20011)%20011;
    }
    return mem[x];
}

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    mem[0]=0;
    mem[1]=1;
    mem[2]=8;


    int n;
    cin>>n;
    // int last=3;
    while(n--){
        ll inp;
        cin>>inp;
        cout<<func(inp)<<"\n";
    }

    return 0;
}


// #include <bits/stdc++.h>
// using namespace std;

// #define ll long long
// const int MOD = 20011;

// vector<ll> mem(20020, -1); // Preallocate memory

// // Bottom-up approach to compute f(x)
// ll func(ll x) {
//     if (x <= 2) return x * x * x; // Base cases
//     if (mem[x] != -1) return mem[x]; // Return if already computed
    
//     // Compute values iteratively
//     for (ll i = 3; i <= x; ++i) {
//         if (mem[i] == -1) {
//             mem[i] = ((mem[i - 3] * mem[i - 3] % MOD * mem[i - 3] % MOD) % MOD +
//                       (mem[i - 2] * mem[i - 1]) % MOD) % MOD;
//         }
//     }
//     return mem[x];
// }

// int main() {
//     ios::sync_with_stdio(0);
//     cin.tie(0);

//     // Base cases
//     mem[0] = 0;
//     mem[1] = 1;
//     mem[2] = 8;

//     int n;
//     cin >> n;
//     while (n--) {
//         ll inp;
//         cin >> inp;
//         cout << func(inp) << "\n";
//     }

//     return 0;
// }