You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
615 B
28 lines
615 B
#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;
|
|
} |