因数
因数的个数

求一个数的全部因数
#include<bits/stdc++.h>
using namespace std;
vector<int> a;
bool yin(int x){
for(int i = 1; i*i <= x; i++){
if(x%i == 0){
a.push_back(i);
if(i!=x/i)a.push_back(x/i);
}
}
}
int main(){
int x; cin >> x;
yin(x);
sort(a.begin(), a.end(), greater<int>() );
for(auto x: a){
cout << x << '\n';
}
return 0;
}
求一个数最大的质因数
for(int i = 2; i*i <= r; i++)
while(r % i == 0) r/= i;

浙公网安备 33010602011771号