首页 > 代码库 > gcd()

gcd()

 1 #include <iostream>
 2 
 3 using namespace std;
 4 #define LL long long
 5 LL gcd(LL a, LL b)
 6 {
 7     if(a < b)
 8     {
 9         LL t = a;
10         a = b;
11         b = t;
12     }
13     return b==0?a:gcd(b, a%b);
14 }
15 int main()
16 {
17     LL a,b;
18     while(cin >> a >> b)
19     {
20         cout  << gcd(a,b) << endl;
21     }
22     return 0;
23 }

 

gcd()