Files
python/TangDou/AcWing/Divisor/869.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

28 lines
642 B
C++

#include <bits/stdc++.h>
using namespace std;
vector<int> nums;
// 求所有约数
void get_divisors(int x) {
for (int i = 1; i <= x / i; i++) // 枚举到sqrt即可
if (x % i == 0) {
nums.push_back(i);
if (i != x / i) nums.push_back(x / i); // 如果 i==x/i 只存储一个,比如 5*5=25
}
sort(nums.begin(), nums.end()); // 排序输出
}
int main() {
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
nums.clear();
get_divisors(x);
for (auto c : nums) printf("%d ", c);
puts("");
}
return 0;
}