求一个数的因子数问题常用的方法是试除法,代码如下:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
int n;cin >> n;
vector<int> factor;
factor.push_back(1);
for(int i=2;i<=sqrt(n);++i){
if(n % i == 0){
factor.push_back(i);
if(n/i != i) factor.push_back(n/i);
}
}
if(n >