Codeforces 1091C New Year and the Sphere Transmission(等差数列与STL set)

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

The person with id 11 initially has a ball. He picks a positive integer kk at most nn, and passes the ball to his kk-th neighbour in the direction of increasing ids, that person passes the ball to his kk-th neighbour in the same direction, and so on until the person with the id 11 gets the ball back. When he gets it back, people do not pass the ball any more.

For instance, if n=6n=6 and k=4k=4, the ball is passed in order [1,5,3,1][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=91+5+3=9.

Find and report the set of possible fun values for all choices of positive integer kk. It can be shown that under the constraints of the problem, the ball always gets back to the 11-st player after finitely many steps, and there are no more than 105105 possible fun values for given nn.

Input

The only line consists of a single integer nn (2≤n≤1092≤n≤109) — the number of people playing with the ball.

Output

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

Output a single line containing mm space separated integers f1f1 through fmfm 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=4k=4 yields fun value 99, as does k=2k=2. Picking k=6k=6 results in fun value of 11. For k=3k=3 we get fun value 55 and with k=1k=1 or k=5k=5 we get 2121.

In the second sample, the values 11, 1010, 2828, 6464 and 136136 are achieved for instance for k=16k=16, 88, 44, 1010 and 1111, respectively.

这个题说白了就是给你一个n,让你枚举间隔为1 to n中某个数时的FUN VALUES,输出时是递增且不重复的一行,说到递增且不重复,我们很容易就想到了SET这个好用的容器。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <cstring>
#include <cmath>
//#include <minmax.h>
#define DETERMINATION main
#define lldin(a) scanf("%lld",&a)
#define din(a) scanf("%d",&a)
#define reset(a,b) memset(a,b,sizeof(a))
const int INF=0x3f3f3f3f;
using namespace std;
typedef long long ll;
const int QUESTION=1e6+500;
/*you can feel the pulse of your destiny...
The nervous feeling fills you with determination.*/
set<ll>sss;
set<ll> ::iterator it;//定义迭代指针
ll n;
ll cal(ll k)
{
  ll ans=((n/k)*(n-k+2))/2;//这是n/k项的等差数列求和公式.
  return ans;
}
int DETERMINATION()
{
    cin>>n;
    for(int i=1;i*i<=n;i++)//只有n是k的倍数的时候这个循环才有可能在有限次数内结束。
    {
       if(n%i!=0)//这不是因子,跳过.
        continue;
       sss.insert(cal(i));//把i这个因子求和放入容器中
       if(i*i!=n)//n不是i的完全平方数,就一定还有n/i这一个因子。
       sss.insert(cal(n/i));
    }
    for(it=sss.begin();it!=sss.end();it++)
    {
      cout<<*it<<" ";//输出即递增.
    }
    cout<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43874261/article/details/88431966