试除法求约数


#include 
#include 
#include 
using namespace std;

vector<int> get_divisors(int x)
{
    vector<int> ans;
    for(int i = 1; i <= x / i; i++)
    {
        if(x % i == 0)
        {
            ans.push_back(i);
            if(i != x / i) ans.push_back(x / i);
        }
    }
    
    sort(ans.begin(), ans.end());
    
    return ans;
}
int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        int a;
        cin >> a;
        
        auto ans = get_divisors(a);
        
        for(auto t : ans) cout << t << ' ';
        cout << endl;
    }
    
    return 0;
}