题解 | #约数的个数#
约数的个数
https://www.nowcoder.com/practice/04c8a5ea209d41798d23b59f053fa4d6?tpId=40&tqId=21334&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan&difficulty=&judgeStatus=&tags=/question-ranking
#include <stdio.h>
int main() {
int a;
while (scanf("%d", &a) != EOF) { // 注意 while 处理多个 case
// 64 位输出请用 printf("%lld") to
int arr[a];
int count[a];
for (int i=0;i<a;i++){
scanf("%d", &arr[i]);
count[i] = 0;
}
for (int i=0;i<a;i++){
for (int j=1;j*j<=arr[i];j++){
if (j * j == arr[i]){
count[i] ++;
}else{
if (arr[i] % j == 0){
count[i] += 2;
}
}
}
}
for (int i=0;i<a;i++){
printf("%d\n", count[i]);
}
}
return 0;
}
查看14道真题和解析