1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int mod = 1e9 + 7; 5 int gcd(int a, int b) { 6 return b ? gcd(b, a % b) : a; 7 } 8 int main() { 9 int n; 10 cin >> n; 11 while (n--) { 12 int a, b; 13 cin >> a >> b; 14 cout << gcd(a, b) << endl; 15 } 16 return 0; 17 }
时间复杂度大致O(log n)