codeforces Good Bye 2018 C. New Year and the Sphere Transmission(數學 ,貝祖定理/羣論)

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 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~n,成環排列,從1開始跳,每次可以跳1、2、3......步,計算出所有步數條件下從1開始再跳回到1所經過的數集的數之和。

思路:

這題可以將題目所描述的條件抽象成一個n階同餘加羣,方便起見,我們將n個數全部減一,羣的幺元爲起點元素0,生成元之一爲元素1,我們從1~n中任取一個元素k,顯然,由該元素可以一個循環子羣,且該子羣所包含的元素就是我們想要求得的每次跳某一步數(k步)條件下從一出發再到一結束的元素們。考慮羣的性質,其子羣的階數只能是n的因子數,且一定包含幺元“0”,所以我們可以枚舉每一個子羣,同時用等差數列求和公式求和該步數下所經過的元素之和。枚舉子羣我們可以枚舉子羣的階數1~n,如果i能夠被n整除,說明有這麼一個階數爲i的子羣,然後其對應的步數(等差求和的d)正好對應(考慮了起點0/1的問題)該子羣生成元所代表的值。該生成元的值=羣的生成元1^(n/對應子羣階數i)。最後,我們可以得到一個o(\sqrt{n})的算法。

AC代碼:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include<algorithm>
#include <set>
#include <queue>
#include <stack>
#include<vector>
#include<map>
#include<ctime>
#define ll long long
using namespace std;
ll ans[110000];
int main()
{
    ll n;
    while(cin>>n)
    {
        memset(ans,0,sizeof(ans));
        int tot=0;
        ll sum=0;
        for(int i=1;i*i<=n;++i)
        {
            if(n%i==0)
            {
                ll nn=n/i;
                ans[++tot]=nn+nn*(nn-1)/2*i;//這裏考慮a1=1;
                ans[++tot]=i+i*(i-1)/2*nn;
            }
        }
        ll pre=-1;
        sort(ans+1,ans+1+tot);
        for(int i=1;i<=tot;++i)
        {
            if(pre!=ans[i])//去重
            {
                cout<<ans[i]<<" ";
                pre=ans[i];
            }
        }
        cout<<endl;
    }
    return 0;
}

 

 

The end;

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章