-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibosum.cpp
More file actions
53 lines (47 loc) · 901 Bytes
/
fibosum.cpp
File metadata and controls
53 lines (47 loc) · 901 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
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
int arr[2][2] = {1, 0, 0, 1};
int[2][2] mult(int a[2][2], int b[2][2]) {
int c[2][2] = {0};
for (int i = 0; i < 2; i ++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
c[i][j] += a[i][k]*b[k][j];
}
}
}
return c;
}
int[2][2] pow(int a[2][2], int b) {
int res[2][2];
res = pow(res, b/2);
res = mult(res, res);
if (b%2 != 0)
res = mult(res, arr);
return res;
}
int fibo(int n) {
return pow(arr, n)[0];
}
int main() {
freopen("input.txt", "r", stdin);
int test_cases, m, n;
cin >> test_cases;
while (test_cases--) {
cin >> m >> n;
cout << fibo(m) << " " << fibo(n) << endl;
}
return 0;
}