Source Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7 , N = 1e6 + 5;
int main() {

    ios_base::sync_with_stdio(0);
    cout.tie(0); cout.tie(0);

    vector<int> dp(N , 0);
    dp[0] = 1;
    for(int i = 1 ; i <= N - 2 ; i++){
        dp[i] = (dp[i - 1] + dp[i]) % mod;
        if(i > 1)
        dp[i] = (dp[i - 2] + dp[i]) % mod;
    }
    int tt;
    cin >> tt;
    while(tt--){
        int n;
        cin >> n;
        cout << dp[n] << '\n';
    }
    return 0;
}
Copy
Study Schedule Greedious
GNU G++17
348 ms
5.2 MB
Accepted