Good Bye 2018 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 n1n-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 10510^5 possible fun values for given nn.

Input

The only line consists of a single integer nn (2n1092 \leq n \leq 10^9) — the number of people playing with the ball.

Output

Suppose the set of all fun values is f1,f2,,fmf_1, f_2, \dots, f_m.

Output a single line containing mm space separated integers f1f_1 through fmf_m in increasing order.

Examples

Input

6

Output

1 5 9 21

Input

16

Output

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.

思路

nn個數圍成一個環,編號是從11nn ,現在你可以隨意選擇一個不超過nn的數kk,從11開始,按照環上字符增大的順序,每隔kk個選擇一個數字,直到回到起點11,然後計算出路徑上不同數字的和,記爲fun value,題目給出你一個數nn,然後讓你求出這nn個數的所有的fun value,從小到大輸出結果。

如果選擇的kknn的因數,那麼一定可以一輪就走完,不同的因數,獲得的fun value的值也不一樣。

當選擇的kk不是nn的因數時,那麼一輪一定走不完,然後直到某一輪走的路徑正好和kknn的因數的某一條路徑重合,所以我們計算kknn的因數的路徑時,已經把這種情況包含了。

所以,利用等差數列求和公式Sn=n(a1+an)2S_n=\frac{n(a_1+a_n)}{2}可以計算出結果。第一項一定爲11,數字的個數就是當前枚舉的ii或者ni\frac{n}{i}.

可以打個表驗證一下:

打表代碼
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
typedef long long ll;
int get_x(int n, int x)
{
    if (x == n)
        return 1;
    int s = x, sum = x + 1;
    while (s != 0)
    {
        s = (s + x) % n;
        sum += (s + 1);
    }
    return sum;
}
set<int> getall_n(int n)
{
    set<int> s;
    for (int i = 1; i <= n; i++)
        s.insert(get_x(n, i));
    return s;
}
int main()
{
    for (int i = 1; i <= 100; i++)
    {
        printf("n=%d:\n", i);
        set<int> s = getall_n(i);
        for (auto x : s)
            printf("%d ", x);
        printf("\n");
    }
    return 0;
}

然後印證了我們的觀點,每個數的答案個數就是他的因子個數。

代碼

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<ll> s;
int main()
{
    ll n;
    scanf("%lld", &n);
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ll x = n / i;
            s.insert((1 + n - i + 1) * x / 2);
            s.insert((1 + n - x + 1) * i / 2);
        }
    }
    for (auto x : s)
        printf("%lld ", x);
    puts("");
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章