题解 | #约数的个数#

约数的个数

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

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

int main() {
    int n;
    while (cin >> n) { 
        for(int i=1;i<=n;i++)
        {
            int x;cin>>x;
            int bound=sqrt(x);
            int count=0;
            for(int j=1;j<=bound;j++)
            {
                
                if(x%j==0)
                {
                    if(j==x/j)count++;
                    else
                    count+=2;
                }
            }
            if(count!=0)cout<<count<<endl;
            
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务