【CF1091C】 New Year and the Sphere Transmission

题目

题意翻译
这题的题意就是nn个人围成一圈,从第一个人开始,每次可以往后跳kk步(1<= k <= n)(1<=k<=n)最后跳回第一个人那里, 对于每个k把它经过的人的编号加起来,假设为f_{k}f
k
​ , 把f_{k}f
k
​ 排序后去重然后输出。

翻译 byby @lahlah @Happynewyear

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

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

For instance, if n = 6 n=6 and k = 4 k=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 = 9 1+5+3=9 .

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

输入输出格式
输入格式:
The only line consists of a single integer n n ( 2 \leq n \leq 10^9 2≤n≤10
9
) — the number of people playing with the ball.

输出格式:
Suppose the set of all fun values is f_1, f_2, \dots, f_m f
1
​ ,f
2
​ ,…,f
m
​ .

Output a single line containing m m space separated integers f_1 f
1
​ through f_m f
m
​ in increasing order.

输入输出样例
输入样例#1: 复制
6
输出样例#1: 复制
1 5 9 21
输入样例#2: 复制
16
输出样例#2: 复制
1 10 28 64 136
说明
In the first sample, we’ve already shown that picking k = 4 k=4 yields fun value 9 9 , as does k = 2 k=2 . Picking k = 6 k=6 results in fun value of 1 1 . For k = 3 k=3 we get fun value 5 5 and with k = 1 k=1 or k = 5 k=5 we get 21 21 .

In the second sample, the values 1 1 , 10 10 , 28 28 , 64 64 and 136 136 are achieved for instance for k = 16 k=16 , 8 8 , 4 4 , 10 10 and 11 11 , respectively.

思路

可以发现每一次选的数的个数都是nn的约数

枚举所有约数,计算答案即可(等差数列求和好评!)

代码

#include <bits/stdc++.h>
#define ll long long
std::vector<ll> v, ans;
void prime(ll n)
{
    for (int i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            v.push_back(i);
            if (i * i != n)
            {
                v.push_back(n / i);
            }
        }
    }
}
std::map<ll, int> m;
int main()
{
    ll n;
    scanf("%I64d", &n);
    prime(n);
    for (int i = 0; i < v.size(); i++)
    {
        m[v[i]] = 1;
    }
    for(std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++)
    {
        ll x = n / it->first;
        ans.push_back((1 + (x * (it->first - 1) + 1)) * (it->first) / 2);
    }
    std::sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++)
        printf("%I64d\n", ans[i]);
    return 0;
}
评论
还没有评论

写下你的评论...
评论
作者: Ouaoan 更新时间: 2019-01-02 17:50  在Ta的博客查看   0 
选定的k一定是n的因数。

代码:

#include<bits/stdc++.h>
using namespace std;

#define read(x) scanf("%d",&x)
#define ll long long

int n;

ll cnt(int d) {
    int x=n/d;
    return (2+((ll)x-1)*d)*x/2;
}

int main() {
    read(n);

    vector<ll> ans;
    for(int i=1;i<=sqrt(n);i++) {
        if(n%i) continue;
        ans.push_back(cnt(i));
        if(i*i!=n) ans.push_back(cnt(n/i));
    }

    sort(ans.begin(),ans.end());

    for(int i=0;i<ans.size();i++) {
        printf("%I64d ",ans[i]);
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值