AcWing 869. 试除法求约数
原题链接
简单
作者:
Drifter
,
2021-01-15 13:30:10
,
所有人可见
,
阅读 251
寒假打卡
1.15 我们很好
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> get_divisors(int x)
{
vector<int> res;
for(int i = 1; i <= x / i; i++)
{
if(x % i == 0)
{
res.push_back(i);
if(i != x / i) res.push_back(x / i);
}
}
sort(res.begin(), res.end());
return res;
} //get_divisors
int main(void)
{
int n;
scanf("%d", &n);
while(n--)
{
int x;
scanf("%d", &x);
auto res = get_divisors(x);
for(auto t: res) printf("%d ",t);
printf("\n");
}
return 0;
}