fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long arr[101] = { 0, 1, 1 };
  6.  
  7. long solution(int n)
  8. {
  9. if (n <= 0) return 0;
  10. else if (n == 1) return 1;
  11. else if (arr[n]) return arr[n];
  12. else return arr[n] = solution(n - 2) + solution(n - 3);
  13. }
  14.  
  15. int main(void)
  16. {
  17. int T, N;
  18. cin >> T;
  19.  
  20. for (int i = 0; i < T; i++)
  21. {
  22. cin >> N;
  23. cout << solution(N) << "\n";
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 4912KB
stdin
2
6
12
stdout
3
16