码迷,mamicode.com
首页 > 其他好文 > 详细

求质因子数

时间:2016-10-23 23:32:25      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:can   space   names   print   int   color   个数   ace   因子   

 

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 int Prim( int n)//求n的质因子个数
 7 {
 8     int i=2,cnt=0;
 9     while(n>0&&n>=i)//防止发生除0错误,因为可能素数还不够50
10     {
11         if(n%i==0)
12         {
13             cnt++;
14             while(n%i==0)
15             {
16                 n=n/i;
17             }
18         }
19         i++;
20     }
21     return cnt;
22 }
23 
24 int main()
25 {
26     int n;
27     scanf("%d",&n);
28     printf("%d",Prim(n));
29     return 0;
30 }

 

求质因子数

标签:can   space   names   print   int   color   个数   ace   因子   

原文地址:http://www.cnblogs.com/TWS-YIFEI/p/5991110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!