题解
2025-04-07 12:26:27
发布于:江苏
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
int A, B;
cin >> A >> B;
int g = gcd(A, B);
vector<int> divisors;
for (int i = 1; i * i <= g; ++i) {
if (g % i == 0) {
divisors.push_back(i);
if (i != g / i) {
divisors.push_back(g / i);
}
}
}
sort(divisors.begin(), divisors.end());
for (int k : divisors) {
cout << k << " ";
}
return 0;
}
这里空空如也
有帮助,赞一个