C. New Year and the Sphere Transmission

本文深入解析了Codeforces竞赛中题目“NewYear和SphereTransmission”的解题思路,介绍了如何通过分析因子来解决球传递问题,并实现算法以找出所有可能的趣味值。

 

http://codeforces.com/contest/1091/problem/C

C. New Year and the Sphere Transmission

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n

people sitting in a circle, numbered from 1 to n in the order in which they are seated. That is, for all i from 1 to n−1, the people with id i and i+1 are adjacent. People with id n and 1

are adjacent as well.

The person with id 1

initially has a ball. He picks a positive integer k at most n, and passes the ball to his k-th neighbour in the direction of increasing ids, that person passes the ball to his k-th neighbour in the same direction, and so on until the person with the id 1

gets the ball back. When he gets it back, people do not pass the ball any more.

For instance, if n=6

and k=4, the ball is passed in order [1,5,3,1]

.

Consider the set of all people that touched the ball. The fun value of the game is the sum of the ids of people that touched it. In the above example, the fun value would be 1+5+3=9

.

Find and report the set of possible fun values for all choices of positive integer k

. It can be shown that under the constraints of the problem, the ball always gets back to the 1-st player after finitely many steps, and there are no more than 105 possible fun values for given n

.

Input

The only line consists of a single integer n

 (2≤n≤109

) — the number of people playing with the ball.

Output

Suppose the set of all fun values is f1,f2,…,fm

.

Output a single line containing m

space separated integers f1 through fm

in increasing order.

Examples

Input

Copy

6

Output

Copy

1 5 9 21

Input

Copy

16

Output

Copy

1 10 28 64 136

Note

In the first sample, we've already shown that picking k=4

yields fun value 9, as does k=2. Picking k=6 results in fun value of 1. For k=3 we get fun value 5 and with k=1 or k=5 we get 21

.

In the second sample, the values 1

, 10, 28, 64 and 136 are achieved for instance for k=16, 8, 4, 10 and 11, respectively.

 

解题思路:

当时比赛的时候出发点就错了,想找规律来着。但是显然这道题就是跟因子有关的。比赛的时候私戳LSD大佬得到正解后,奈何因为LL没过。我到现在都不知道为啥不用LL就过不了,明明没超LL啊啊啊啊啊!有点生气。

画一画就可以看出,把所有的因子按照等差数列的式子求个和,放在set里一下就出了。

得到的教训是:这种的转圈圈的一下就要往因子上边去靠。

详见代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
     set<LL>st;
     set<LL>::iterator it,itt;
     for(LL i=1;i<=sqrt(n);i++){

            if(n%i!=0){
                continue;
            }
           /// cout<<"i:"<<i<<endl;
            LL ans=0;

            ans=(1+(n-1)/i*i+1)*(n/i)/2;
            st.insert(ans);
            LL ii=n/i;
            ans=(1+(n-1)/ii*ii+1)*(n/ii)/2;
            st.insert(ans);

        }
        for(it=st.begin();it!=st.end();it++)
       {
         printf("%lld ",*it);
       }
       cout<<endl;
    }

}

ps:

goodbye2018真的是掉分场。。。呜呜呜。。。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值