试除法求约数

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;
}

posted @ 2022-12-08 21:15  山海自有归期  阅读(13)  评论(0编辑  收藏  举报