题解 | 质因数的个数

质因数的个数

https://www.nowcoder.com/practice/20426b85f7fc4ba8b0844cc04807fbd9

#include <stdio.h>
#include <math.h>

int primeFactorCount(int n);

int main() {
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",primeFactorCount(n));
    }
    return 0;
}

int primeFactorCount(int n){
    int count=0;
    while(n%2==0){
        n/=2;
        count++;
    }
    for(int i=3;i<=n;){
        if(n%i==0){
            n/=i;
            count++;
        }else i+=2;
    }
    return count;
}

全部评论

相关推荐

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

创作者周榜

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