题解 | #约数的个数#

约数的个数

https://www.nowcoder.com/practice/04c8a5ea209d41798d23b59f053fa4d6

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const int MAX=1001;
int numbers[MAX];

int main() {
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n==0){
            break;
        }
        for(int i=0;i<n;i++){
            scanf("%d",&numbers[i]);
        }
        for(int i=0;i<n;i++){
            int answer=0;
            int bound=sqrt(numbers[i]);
            for(int j=1;j<=bound;j++){
                if(numbers[i]%j==0){
                    answer=answer+2;
                }

            }
            if(bound*bound == numbers[i]){
                answer--;
            }
            printf("%d\n",answer);
        }

    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务