#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long x, y, temp;
if (a > b) {
x = b, y = a;
}
else {
x = a, y = b;
}
temp = y % x;
while (temp > 0) {
y = x;
x = temp;
temp = y % x;
}
return x;
}
int main() {
long long m, n;
while (cin >> m >> n) {
long long ans = gcd(m, n);
cout << ans << endl ;
}
return 0;
}
辗转相除法求最大公因数。
猜你喜欢
转载自blog.csdn.net/weixin_46130146/article/details/104069100
今日推荐
周排行