Algorithm/백준
C++ 알고리즘 - 백준 24416 알고리즘 수업 - 피보나치 수 1
마루설아
2025. 1. 21. 21:13
https://www.acmicpc.net/problem/24416
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
/******** 전역변수 ********/
int fibo[50] = { 0, 1, 1, };
int cnt1 = 0, cnt2 = 0;
/******** 함 수 ********/
int fibonacci(int n) {
if (n == 1 || n == 2) {
cnt1++;
return 1;
}
else return fibonacci(n - 1) + fibonacci(n - 2);
}
int main(void) {
/******** C++ INIT ********/
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/******** 지역변수 ********/
int input;
/******** 구 현 ********/
cin >> input;
fibonacci(input);
cout << cnt1 << " ";
for (int i = 3; i <= input; i++) {
fibo[i] = fibo[i - 1] + fibo[i - 2];
cnt2++;
}
cout << cnt2;
}