分解因子:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 9;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
vector<ll> v;
for (ll i = 1; i <= n / i; i++)
{
if (n % i) continue;
v.push_back(i);
if (i * i != n) v.push_back(n / i);
}
sort(begin(v), end(v));
for (auto& i : v) cout << i << ' ';
return 0;
}
分解质因子:
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
vector<ll>v;
void solve()
{
ll n;cin>>n;
for(int i=2;i<=n/i;++i)
{
if(n%i)continue;
v.push_back(i);
while(n%i==0)n/=i;
}
if(n>1)v.push_back(n);
sort(v.begin(),v.end());
for(auto &i :v)cout<<i<<' ';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
solve();
return 0;
}
标签:int,ll,cin,long,因子,分解,&&,using
From: https://blog.csdn.net/shadow2kkkk/article/details/137504749