1. 程式人生 > >C. New Year and the Sphere Transmission

C. New Year and the Sphere Transmission

                                       C. New Year and the Sphere Transmission

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.

#include<bits/stdc++.h>
using namespace std;
const int Maxn=210000;

int n,num;
ll x[Maxn];

void work(int n,int k) {
    ll d=n/k;
    x[++num]=n*(d-1)/2+d;
}

int main() {
    scanf("%d",&n);
    for(int i=1;i*i<=n;i++)
        if(n%i==0) {
            work(n,i);
            work(n,n/i);
        }
    sort(x+1,x+num+1);
    for(int i=1;i<=num;i++) if(x[i]!=x[i-1]) printf("%I64d ",x[i]);
    return 0;
}