题解 | #约数的个数#

约数的个数

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

#include <iostream>
#include "cmath"
using namespace std;

int main() {
    int n;
    while (cin >> n) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        while (n--) {
            int a;
            cin >> a;
            int bound = sqrt(a);
            int count = 0;
            for (int i = 1; i <= bound; i++) {
                if (a % i == 0) count += 2;
            }
            if (a == 1) count=1;
            else if (bound * bound == a) {
                count--;
            }
            cout<<count<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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