Shirlies
宁静专注认真的程序媛~

每做一题就对数学更加崇拜!

看了别人做的才会做的,细节问题不会处理

http://www.mysjtu.com/page/M0/S653/653211.html

还是贴上自己的代码吧。。。

代码如下:
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cmath>
 4 
 5 int n;
 6 
 7 long long solve()
 8 {
 9     int m = (int)sqrt(n + 0.5);
10     long long sum = 0;
11     int count = 0;
12     for(int i = 2;i <= m;i ++)
13     {
14         if(n % i == 0)
15         {
16             int mul = 1;
17             while(n % i == 0)
18             {
19                 mul *= i;
20                 n = n/i;
21             }
22             sum += mul;
23             count ++;
24         }
25     }
26     if(n != 1 || count == 0)
27     {
28         sum += n;
29         count ++;
30     }
31     if(count == 1)
32         sum ++;
33     return sum;
34 }
35 
36 int main()
37 {
38     int cas = 1;
39     while(scanf("%d",&n) == 1)
40     {
41         if(!n)
42             break;
43         printf("Case %d: ",cas ++);
44         printf("%lld\n",solve());
45     }
46 
47     return 0;
48 }

 

posted on 2012-04-14 17:40  Shirlies  阅读(192)  评论(0编辑  收藏  举报