-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgcd.cpp
More file actions
59 lines (48 loc) · 1.01 KB
/
gcd.cpp
File metadata and controls
59 lines (48 loc) · 1.01 KB
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
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vvi vector<vector<int>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define endl "\n"
#define forin(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define fordec(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define tc_ll \
lli t; \
cin >> t; \
while (t--)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int mod(int x)
{
return x >= 0 ? x : -x;
}
// recursive algorithm for finding GCD in O(log(max(a,b))) time
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, (a % b));
}
int main()
{
fast
tc_ll
{
int a, b;
cin >> a >> b;
cout << gcd(a, b) << endl;
}
return 0;
}