Source Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define sp ' '
#define assert(x,a) if(x){cout << a << endl;return;}
#define sortv(x)sort(x.begin(),x.end())
#define revev(x)reverse(x.begin(),x.end())
ll ans1 = 0;
long long f[10000003];
long long npr[10000003];
inline void fast(){
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    }
vector<vector<int>>graph;

vector<bool>vis(100001,false);
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
inline void answer(int c){assert(c==0,"NO")cout << "YES" << endl;}
void solve()
{
    ll n;cin >> n;
    cout << npr[n] << endl;
}
int main()
{
    fast();
	npr[0] = 0;
	npr[1] = 1;
	npr[2] = 2;
	npr[3] = 3;
      for(int i = 4 ; i <= 10000002 ; i++)
      {
          npr[i] = (npr[i] + npr[i - 1] + npr[i - 2]) % 1000000007;
      }
    ll t{ 1 };cin >> t;
  // cin.ignore();
    while (t--)
    {
        solve();
    }
}
Copy
Study Schedule iwjx
GNU G++17
214 ms
79.7 MB
Accepted