fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define M 1000000007
  4. #define rep(i,s,n) for(long int i=s;i<n;i++)
  5. using namespace std;
  6.  
  7. const int mx = 1000010;
  8.  
  9. ll dp[1000010],temp;
  10.  
  11. int main() {
  12. dp[0]=2;dp[1]=7;dp[2]=9;
  13. rep(i,3,mx)
  14. dp[i]= (dp[i-1]+(2*dp[i-2]%M) + dp[i-3])%M;
  15. int t;
  16. cin >> t;
  17. while(t--){
  18. cin >> temp;
  19. cout << dp[temp-1]%M <<endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0.07s 11112KB
stdin
2
2
4
stdout
7
25