分解质因数法求因数个数
代码:
#include<iostream>
using namespace std;
int solve(int x){
int cnt,ans=1;
for(int i=2;i<=x/i;++i){
if(x%i==0){
cnt=1;
while(x%i==0){
x/=i;
cnt++;
}
ans*=cnt;
}
}
if(x>1) ans*=2;
return ans;
}
int main(){
int n;
while(~scanf("%d",&n)){
int x;
for(int i=1;i<=n;++i) {
scanf("%d",&x);
printf("%d\n",solve(x));
}
}
}