一道循环题,不知道怎么控制(求助)
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 编辑 ]