| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 627 人关注过本帖
标题:一道循环题,不知道怎么控制(求助)
只看楼主 加入收藏
jtyf1314
Rank: 1
来 自:台州
等 级:新手上路
帖 子:6
专家分:2
注 册:2012-6-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
一道循环题,不知道怎么控制(求助)
http://acm.tzc.
Pebbles Game   
时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte
总提交: 11            测试通过: 7
描述


The fool ZZD from TZU decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the ZZD has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the ZZD must use all the pebbles he has, i. e. n = a·b.

Once the fool ZZD has arranged the pebbles, he takes back any of the resulting rows (that is, b pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of a and b) and takes back one row, and so on. The game continues until at some point the ZZD ends up with exactly one pebble.

The game process can be represented as a finite sequence of integers c1, ..., ck, where:

c1 = n
ci + 1 is the number of pebbles that the ZZD ends up with after the i-th move, that is, the number of pebbles in a row after some arrangement of ci pebbles (1 ≤ i < k). Note that ci > ci + 1.
ck = 1
The result of the game is the sum of numbers ci. You are given n. Find the maximum possible result of the game.


输入


The single line of the input contains a single integer n — the initial number of pebbles the fool ZZD has.

2 ≤ n ≤ 109


输出


Print a single number — the maximum possible result of the game.


样例输入

10
8


样例输出


16
15


提示

Consider the first example (c1 = 10). The possible options for the game development are:

Arrange the pebbles in 10 rows, one pebble per row. Then c2 = 1, and the game ends after the first move with the result of 11.

Arrange the pebbles in 5 rows, two pebbles per row. Then c2 = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. c3 = 1, and the game ends with the result of 13.

Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to c2 = 5, c3 = 1, and the game ends with the result of 16 — the maximum possible result.


我对这道题目的理解是
输入一个n,n除以一个数得到m,类似的,直到m等于1;把m求和,然后比较各种情况下得到的和,最大的输出;
我可以写出n的所以约数之后的代码
#include<stdio.h>
int main()
{
    __int64 n,i,sum;
    while(scanf("%I64d",&n)!=EOF)
    {    sum=0;
        for(i=1;i<=n;i++)
        {
            if(n%i==0)
            sum+=i;
        }
        printf("%I64d\n",sum);
    }
    return 0;
}
但这题我循环不知道怎么控制。
我说c语言的初学者,希望高手帮帮忙

[ 本帖最后由 jtyf1314 于 2012-6-9 23:15 编辑 ]
搜索更多相关主题的帖子: game 测试 nothing decided turned 
2012-06-09 22:45
never_yzq
Rank: 4
等 级:业余侠客
帖 子:112
专家分:213
注 册:2012-5-25
收藏
得分:5 
__int64 ,"%I64d这些是什么东东?不明白!
2012-06-10 12:16
xunxun
Rank: 2
等 级:论坛游民
帖 子:6
专家分:17
注 册:2012-6-10
收藏
得分:5 
好长。。。。。。。。。。
2012-06-10 15:07
简体字01
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:86
专家分:137
注 册:2012-3-4
收藏
得分:5 
英语。。。压力好大。
2012-06-10 16:14
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:5 
真扯,你们学校的题目描述太不精确了,我还以为是单组数据测试呢,结果是多组数据。
考的其实是质因数分解。0ms AC
程序代码:
#include<stdio.h>
#include<math.h>

int cal(int n)
{
    int s, q, i;
    for(s = n; n > 2 && !(n & 1); s += n >>= 1);
    for(q = (int)sqrt(n), i = 3; i <= q; i++)
        if(n % i == 0)
        {
            do s += n /= i; while(n % i == 0);
            q = (int)sqrt(n);
        }
    return s + 1;
}

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

重剑无锋,大巧不工
2012-06-10 17:25
快速回复:一道循环题,不知道怎么控制(求助)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019139 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved