반응형
python
import sys
N = int(sys.stdin.readline())
arr = [0 for _ in range(N+1)]
arr[1] = 1
for i in range(2, N+1):
arr[i] = arr[i-1] + arr[i-2]
print(arr[-1])
c++
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
long *arr = new long[n+1];
arr[0] = 0;
arr[1] = 1;
for (int i = 2; i <= n; i++){
arr[i] = arr[i - 1] + arr[i - 2];
}
cout << arr[n];
return 0;
}
반응형