Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
#define clr(d,v) memset(d,v,sizeof(d))
#define ll long long
#define ld long double
#define ull unsigned long long
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
ll gcd(ll x, ll y) { return(!y) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return((x / gcd(x, y)) * y); }
void file()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int dp[N];
int n = (int)1e6+3;
int solve(int idx)
{
    if (idx == 0)
    {
        return 1;
    }
    if (idx < 0)
        return 0;
    int& ret = dp[idx];
    if (~ret)return ret;
    ret = 0;
    ret = (solve(idx - 1) % mod + solve(idx - 2) % mod) % mod;
    return ret;
}
int main()
{
    file();
    clr(dp, -1);
    int t;
    cin >> t;
    solve(n);
    while (t--)
    {
        cin >> n;
        cout << dp[n] << "\n";
    }
}

 
Copy
Study Schedule Abo_Samrah
GNU G++17
105 ms
52.2 MB
Accepted