fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int arr[1000001] = { 0, 1, 2 };
  6.  
  7. int 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 - 1) + solution(n - 2)) % 15746;
  13. }
  14. int main(void)
  15. {
  16. int N;
  17. cin >> N;
  18. cout << solution(N);
  19. return 0;
  20. }
Success #stdin #stdout 0s 4888KB
stdin
4
stdout
5