-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1003.cpp
More file actions
41 lines (33 loc) · 677 Bytes
/
1003.cpp
File metadata and controls
41 lines (33 loc) · 677 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
#include <iostream>
#include <vector>
using namespace std;
vector<int> v(41);
int fibo(int n){
if(n == 0){
v[0] = 0;
return 0;
}
else if(n == 1){
v[1] = 1;
return 1;
}
if(v[n] != 0) return v[n];
else return v[n] = fibo(n-1) + fibo(n-2);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t;
cin >> t;
for(int i=0; i<t; i++){
int n;
cin >> n;
if(n == 0) cout << "1 0" << "\n";
else if(n == 1) cout << "0 1" << "\n";
else
{
fibo(n);
cout << v[n-1] << " " << v[n] << "\n";
}
}
return 0;
}