题目描述
输入n个整数,依次输出每个数的约数的个数
输入描述:
输入的第一行为N,即数组的个数(N<=1000) 接下来的1行包括N个整数,其中每个数的范围为(1<=Num<=1000000000) 当N=0时输入结束。
输出描述:
可能有多组输入数据,对于每组输入数据, 输出N行,其中每一行对应上面的一个数的约数的个数。
示例1
输入
复制
5 1 3 4 6 12
输出
复制
1 2 3 4 6
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long LL ;
const int MAX = 1000005 ;
LL n ;
vector<LL> fac[MAX] ;
LL ans[MAX] ;
int factor[MAX] ;
LL solve(LL n){
int cnt = 0 ;
for(LL i = 1 ; i*i <=n ; i++ ) {
if(n%i == 0 ){
cnt++ ;
if(i!=n/i){
cnt++ ;
}
}
}
return cnt ;
}
int main() {
while(cin >> n){
for(int i = 1 ; i<=n ; i++ ){
LL x ;
cin >> x ;
cout<<solve(x)<<endl;
}
}
return 0 ;
}