-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1916_4.cpp
More file actions
44 lines (31 loc) · 712 Bytes
/
Copy path1916_4.cpp
File metadata and controls
44 lines (31 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 1916 : (재귀함수) 피보나치 수열 (Large) - Trial 4
// 2023.10.16
#include <iostream>
#include <vector>
#define endl '\n'
#define test
using namespace std;
vector<int> bottomUp;
int Fibonacci(int n, int m)
{
if (m <= 2)
bottomUp[m] = 1;
else
bottomUp[m] = (bottomUp[m-1] + bottomUp[m-2]) % 10009;
#ifdef test
cout << m << ' ' << bottomUp[m] << endl;
#endif
if (m == n)
return bottomUp[m];
else
Fibonacci(n, m + 1);
}
int main()
{
int n;
cin >> n;
bottomUp.assign(n + 1, -1); // not 0 but -1 (∵ 10009 % 10009 = 0)
cout << Fibonacci(n, 1) << endl;
return 0;
}
// Runtime Error:Segmentation fault