알고리즘

C++ 알고리즘 - 백준 1003 피보나치 함수

마루설아 2025. 1. 4. 20:15

https://www.acmicpc.net/problem/1003

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(void) {
	/************** C++ Init **************/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/************** C++ Init **************/

	int input1, input2;
	vector<int> v;
	cin >> input1;

	v.push_back(1);
	v.push_back(1);

	for (int i = 2; i < 41; i++) {
		v.push_back(v[i - 2] + v[i - 1]);
	}

	for (int i = 0; i < input1; i++) {
		cin >> input2;
		
		if (input2 == 0) cout << 1 << " " << 0 << endl;
		else if (input2 == 1) cout << 0 << " " << 1 << endl;
		else cout << v[input2 - 2] << " " << v[input2 - 1] << endl;
	}
}