Background
给出一个整数n,将n的因数从小到大输出
Description
第一行给出一个整数TMATH:0:(1≤n≤1e12)TMATH:0:(1≤n≤1e12),代表要进行因数分解的的整数
保证
Input
从小到大输出n的因数,每一个n的因数占一行
Sample 1
Inputcopy | Outputcopy |
---|---|
3 1 2 3 | 1 1 2 1 3 |
#include <bits/stdc++.h>
#define endl '\n'
#define buff ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpll;
const ll MAX_INT=0x3f3f3f3f;
const ll MAX_LL=0x3f3f3f3f3f3f3f3f;
const ll CF=2e5+9;
const ll mod=1e9+7;
int main()
{
int T;
cin >> T;
while(T--)
{
ll n;
cin >> n;
vll factors;
for(ll i = 1; i * i <= n; ++i)
{
if (n % i == 0)
{
factors.push_back(i);
if(i != n / i)
{
factors.push_back(n / i);
}
}
}
sort(factors.begin(), factors.end());
for(int i = 0; i < factors.size(); ++i)
{
cout << factors[i];
if(i != factors.size() - 1)
{
cout << " ";
}
}
cout << endl;
}
}